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

github-issues.ts

39 lines · 1.3 KB · TypeScript
import type { Signal, SignalAdapter } from '../types.ts'

export const githubIssuesAdapter: SignalAdapter = {
	id: 'github-issues',
	displayName: 'GitHub issues',
	normalize(raw, ctx) {
		const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
		const issue = (rec.issue as Record<string, unknown> | undefined) ?? rec
		const number = issue.number ?? rec.number
		const repo =
			(rec.repository as Record<string, unknown> | undefined)?.full_name ??
			rec.repo ??
			null
		const labelsRaw = issue.labels
		const labels: string[] = Array.isArray(labelsRaw)
			? labelsRaw.map((l) =>
					typeof l === 'string' ? l : String((l as { name?: string }).name ?? ''),
				)
			: []
		const externalId = String(number ?? issue.id ?? 'unknown')
		const signal: Signal = {
			id: `sig_${crypto.randomUUID().replace(/-/g, '').slice(0, 12)}`,
			projectId: ctx.projectId,
			source: 'github-issues',
			externalId,
			fingerprint: `github-issue:${repo ?? 'unknown'}:${externalId}`,
			title: String(issue.title ?? 'GitHub issue'),
			body: String(issue.body ?? ''),
			severity: 'medium',
			labels,
			links: issue.html_url
				? [{ label: 'Issue', url: String(issue.html_url) }]
				: [],
			repoRef: repo ? String(repo) : null,
			receivedAt: new Date().toISOString(),
		}
		return [signal]
	},
}