Skip to content
← Public packages

@kentcdodds/codebase-cleanup

Cursor cloud agents for legacy cleanup, docs freshness, tight tests, and prod CI fixes, plus a weekly Devin general audit.

FollowFork

Files

ci-episode.ts

74 lines · 2.2 KB · TypeScript
import { normalizeRepoSlug } from './shared.ts'
import {
	claimCiEpisode,
	closeCiEpisode,
	getCiEpisode,
	listCiEpisodes,
	type CiEpisode,
} from './storage.ts'

/**
 * List prod-ci-failure red episodes (one row per repo + branch).
 *
 * @example
 * import { list } from 'kody:@kentcdodds/codebase-cleanup/ci-episode'
 * await list()
 */
export async function list() {
	return await listCiEpisodes()
}

/**
 * Mark a red branch as already handled (for example a manual Cursor agent is
 * on it), so prod-ci-failure launches nothing until the head goes green and
 * fails again. Idempotent: if an episode is already open, it is left as is.
 *
 * @example
 * import { markHandled } from 'kody:@kentcdodds/codebase-cleanup/ci-episode'
 * await markHandled({ repo: 'acme/widgets', branch: 'main', sha: 'abc123', note: 'Manual agent on it' })
 */
export async function markHandled(input: {
	repo: string
	branch: string
	sha?: string | null
	note: string
	agentId?: string | null
	agentUrl?: string | null
}) {
	if (!input?.repo || !input?.branch || typeof input.note !== 'string' || !input.note.trim()) {
		throw new Error('repo, branch and note are required')
	}
	const repo = normalizeRepoSlug(input.repo)
	const claimed = await claimCiEpisode({
		repo,
		branch: input.branch,
		sha: input.sha ?? null,
		source: 'manual',
		note: input.note.trim(),
		agentId: input.agentId ?? null,
		agentUrl: input.agentUrl ?? null,
	})
	return { claimed, episode: (await getCiEpisode(repo, input.branch)) as CiEpisode | null }
}

/**
 * Close an open episode by hand (normally the re-check closes it when the head
 * goes green). The next red head can launch again.
 *
 * @example
 * import { reset } from 'kody:@kentcdodds/codebase-cleanup/ci-episode'
 * await reset({ repo: 'acme/widgets', branch: 'main', note: 'fixed manually' })
 */
export async function reset(input: { repo: string; branch: string; note?: string }) {
	if (!input?.repo || !input?.branch) throw new Error('repo and branch are required')
	const repo = normalizeRepoSlug(input.repo)
	const closed = await closeCiEpisode({
		repo,
		branch: input.branch,
		sha: null,
		note: input.note ?? 'reset by hand',
	})
	return { closed, episode: await getCiEpisode(repo, input.branch) }
}

export default { list, markHandled, reset }