import type { Signal, SignalAdapter } from '../types.ts' export const ciFailureAdapter: SignalAdapter = { id: 'ci-failure', displayName: 'CI failure', normalize(raw, ctx) { const rec = (raw && typeof raw === 'object' ? raw : {}) as Record const repo = (rec.repository as Record | undefined)?.full_name ?? rec.repo const suite = (rec.check_suite as Record | undefined) ?? {} const run = (rec.workflow_run as Record | undefined) ?? {} const headSha = String(suite.head_sha ?? run.head_sha ?? rec.head_sha ?? 'unknown') const branch = String(suite.head_branch ?? run.head_branch ?? rec.branch ?? 'main') const signal: Signal = { id: `sig_${crypto.randomUUID().replace(/-/g, '').slice(0, 12)}`, projectId: ctx.projectId, source: 'ci-failure', externalId: headSha, fingerprint: `ci-failure:${repo ?? 'repo'}:${branch}:${headSha}`, title: `CI red on ${repo ?? 'repo'}@${branch}`, body: `Head ${headSha} failed required checks.`, severity: 'high', labels: ['ci', 'prod-ci-failure'], links: [], repoRef: repo ? String(repo) : null, receivedAt: new Date().toISOString(), } return [signal] }, }