// What the forge's events ask of the announcer, and the one pass at a start (issue 1422, notes 10 and 11). Nothing polls the // forge for heads: a pull request's new head is said as pull.updated when its event is heard, a merge or a close by its // event and by the pass over every repository's merges at the start (design 47 H §764; H-A-100). // // Apart from index.ts, which has side effects at import, so these are tested with the announcers injected. import type { ForgeEvent } from "./webhook.js"; export interface ActDeps { getRepo(owner: string, repo: string): Promise; getPull(owner: string, repo: string, number: number): Promise

; announceUpdated(repo: R, pull: P): Promise; announceMerge(repo: R, pull: P): Promise; announceClosed(repo: R, pull: P): Promise; } const HEAD_EVENTS = ["forge.pull-request.opened", "forge.pull-request.synchronized", "forge.pull-request.reopened"]; /** * What the forge's event asks of the announcer at once: a new head is said, a merge, a close without a merge, and a pull * request retargeted (an edit: the head is said into the base it now has). */ export async function actOn(event: ForgeEvent, d: ActDeps): Promise { const b = event.body as { owner?: string; repo?: string; number?: number; merged?: boolean }; if (!b.owner || !b.repo || !b.number) return; const edited = event.name === "forge.pull-request.edited"; const closed = event.name === "forge.pull-request.closed"; const head = HEAD_EVENTS.includes(event.name) || edited; const merged = event.name === "forge.pull-request.merged"; if (!head && !merged && !closed) return; if (closed && b.merged) return; // a merge is weighed with its own event (ADR 0382 §5) const [repo, pull] = await Promise.all([d.getRepo(b.owner, b.repo), d.getPull(b.owner, b.repo, b.number)]); if (closed) { await d.announceClosed(repo, pull); return; } if (head && pull.state === "open") await d.announceUpdated(repo, pull); if (merged) await d.announceMerge(repo, pull); }