openContribution
Open a contribution of source into target (both branches here), or find the open one there already is.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { ContributionError } from "#codebase/tcmts/cli/contributions"; export function openContribution( cb: Codebase, c: { title: string; description: string; source: string; target: string; author: string }, ): { id: number; created: boolean } { for (const b of [c.source, c.target]) if (!cb.store.hasBranch(b)) throw new ContributionError(`no branch '${b}' here`); if (c.source === c.target) throw new ContributionError("a branch can't be contributed to itself"); const open = cb.store.openContribution(c.source, c.target); if (open) { cb.store.touchContribution(open.id); return { id: open.id, created: false }; } return { id: cb.store.createContribution(c), created: true }; }