feat(hub): accept and expose paperclip_project_id on error records (BIT-25537)
- php-error bridge: accept paperclip_project_id / paperclipProjectId in CrmPhpPayload and promote into event context alongside project_slug/gitea_repo - recent-errors: extract paperclip_project_id from context_json and emit as top-level field so error loop can route issues to the correct project board column without falling back to PAPERCLIP_ERROR_LOOP_PROJECT_ID_BY_SLUG - Add tests for include/omit behaviour (mirrors gitea_repo coverage) - Update ERROR_MONITORING_PUBLIC_API.md to document both optional fields No DB migration required: field is stored in existing context_json column. Co-Authored-By: Paperclip <[email protected]>
This commit is contained in:
1 parent
be735a16b6
commit
3c307ea32d
4 files changed
+78
No files matched your search
@@ -84,4 +84,60 @@ describe('GET /api/error-monitoring/recent-errors', () => {
|
||||
const body = res.json() as { data: Array<{ gitea_repo?: string }> };
|
||||
expect(body.data[0].gitea_repo).toBeUndefined();
|
||||
});
|
||||
|
||||
it('includes top-level paperclip_project_id when stored in context_json', async () => {
|
||||
const execute = vi.fn().mockResolvedValue([
|
||||
[
|
||||
{
|
||||
incident_id: '2',
|
||||
occurrence_id: '100',
|
||||
project_slug: 'crm',
|
||||
incident_severity: 'high',
|
||||
incident_state: 'open',
|
||||
message: 'probe',
|
||||
stack_trace: '',
|
||||
context_json: JSON.stringify({
|
||||
paperclip_project_id: 'dba3fc26-c728-4e51-a23c-083881a2f534',
|
||||
}),
|
||||
environment: 'production',
|
||||
occurred_at: '2026-01-01T00:00:00.000Z',
|
||||
} as RowDataPacket,
|
||||
],
|
||||
]);
|
||||
const app = await buildApp(execute);
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/error-monitoring/recent-errors?api_key=test-recent-errors-key',
|
||||
});
|
||||
expect(res.statusCode).toBe(200);
|
||||
const body = res.json() as { data: Array<{ paperclip_project_id?: string }> };
|
||||
expect(body.data[0].paperclip_project_id).toBe('dba3fc26-c728-4e51-a23c-083881a2f534');
|
||||
});
|
||||
|
||||
it('omits paperclip_project_id when not present in context', async () => {
|
||||
const execute = vi.fn().mockResolvedValue([
|
||||
[
|
||||
{
|
||||
incident_id: '3',
|
||||
occurrence_id: '101',
|
||||
project_slug: 'wdmi-store',
|
||||
incident_severity: 'low',
|
||||
incident_state: 'open',
|
||||
message: 'y',
|
||||
stack_trace: '',
|
||||
context_json: JSON.stringify({ project_slug: 'wdmi-store' }),
|
||||
environment: 'production',
|
||||
occurred_at: '2026-01-01T00:00:00.000Z',
|
||||
} as RowDataPacket,
|
||||
],
|
||||
]);
|
||||
const app = await buildApp(execute);
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/error-monitoring/recent-errors?api_key=test-recent-errors-key',
|
||||
});
|
||||
expect(res.statusCode).toBe(200);
|
||||
const body = res.json() as { data: Array<{ paperclip_project_id?: string }> };
|
||||
expect(body.data[0].paperclip_project_id).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -74,6 +74,15 @@ function extractGiteaRepo(ctx: Record<string, unknown> | null): string {
|
||||
return typeof raw === 'string' ? raw.trim() : '';
|
||||
}
|
||||
|
||||
/** Paperclip error loop reads top-level `paperclip_project_id` to route issues to the correct project. */
|
||||
function extractPaperclipProjectId(ctx: Record<string, unknown> | null): string {
|
||||
if (!ctx) {
|
||||
return '';
|
||||
}
|
||||
const raw = ctx.paperclip_project_id ?? ctx.paperclipProjectId;
|
||||
return typeof raw === 'string' ? raw.trim() : '';
|
||||
}
|
||||
|
||||
function parseStatusList(raw: string | undefined): string[] | null {
|
||||
if (raw == null || raw.trim() === '') {
|
||||
return ['open', 'investigating'];
|
||||
@@ -211,6 +220,7 @@ async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply):
|
||||
const ctx = parseJsonObject(row.context_json != null ? String(row.context_json) : null);
|
||||
const { file_path, line_number } = extractFileLine(ctx);
|
||||
const gitea_repo = extractGiteaRepo(ctx);
|
||||
const paperclip_project_id = extractPaperclipProjectId(ctx);
|
||||
const incSev = String(row.incident_severity ?? 'medium').toLowerCase();
|
||||
const sev = ['critical', 'high', 'medium', 'low'].includes(incSev) ? incSev : 'medium';
|
||||
const st = String(row.incident_state ?? 'open').toLowerCase();
|
||||
@@ -238,6 +248,9 @@ async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply):
|
||||
if (gitea_repo !== '') {
|
||||
rowOut.gitea_repo = gitea_repo;
|
||||
}
|
||||
if (paperclip_project_id !== '') {
|
||||
rowOut.paperclip_project_id = paperclip_project_id;
|
||||
}
|
||||
return rowOut;
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user