import type { JsonValue } from "./types";
function text(value: JsonValue | undefined): string {
return value === undefined || value === null ? "" : String(value);
}
/** Timeline copy for pull request review and merge-automation events. */
export function pullEventText(kind: string, data: { [key: string]: JsonValue }): string | null {
switch (kind) {
case "review_dismissed":
return `dismissed a review: ${text(data.reason)}`;
case "issue_linked":
return `linked issue #${text(data.number)}`;
case "issue_unlinked":
return `unlinked issue #${text(data.number)}`;
case "auto_merge_enabled":
return data.stack
? `enabled auto-merge (${text(data.method)}) to merge the stack up to #${text(data.stack)}`
: `enabled auto-merge (${text(data.method)})`;
case "restacked":
return `restacked this onto ${text(data.onto)} after #${text(data.parent)} changed`;
case "restack_failed":
return `could not restack this after #${text(data.parent)} changed: ${text(data.reason)}`;
case "auto_merge_disabled":
return data.reason ? `auto-merge was disabled: ${text(data.reason)}` : "disabled auto-merge";
case "added_to_merge_queue":
return "added this to the merge queue";
case "removed_from_merge_queue":
return data.reason
? `was removed from the merge queue: ${text(data.reason)}`
: "removed this from the merge queue";
default:
return null;
}
}