Skip to content
← Public packages

@kody/kody-factory

Forkable multi-project software factory: signals, priority queue, project UI, sweep job. Agent runners and Sentry reach it by events.

FollowFork

Files

ci-failure.ts

30 lines · 1.2 KB · TypeScript
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<string, unknown>
		const repo =
			(rec.repository as Record<string, unknown> | undefined)?.full_name ?? rec.repo
		const suite = (rec.check_suite as Record<string, unknown> | undefined) ?? {}
		const run = (rec.workflow_run as Record<string, unknown> | 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]
	},
}