diff --git a/modules/gitea/pulls.ts b/modules/gitea/pulls.ts index 0c8fb96a..602013a8 100644 --- a/modules/gitea/pulls.ts +++ b/modules/gitea/pulls.ts @@ -25,7 +25,7 @@ export const CHECK_STATUS = "mesh/check"; /** The statuses a branch's rule requires, from the rule the forge applies to it: none when it is unprotected or checks * no status; undefined when the rule could not be read. */ -export function requiredOf(rule: { enable_status_check?: boolean; status_check_contexts?: string[] } | null | undefined): string[] | undefined { +export function requiredOf(rule: { enable_status_check?: boolean; status_check_contexts?: string[] | null } | null | undefined): string[] | undefined { if (rule === undefined) return undefined; if (!rule || !rule.enable_status_check) return []; return (rule.status_check_contexts ?? []).filter(Boolean); diff --git a/modules/gitea/test/pulls.test.ts b/modules/gitea/test/pulls.test.ts index bb3d257b..fcecc44b 100644 --- a/modules/gitea/test/pulls.test.ts +++ b/modules/gitea/test/pulls.test.ts @@ -216,3 +216,12 @@ test("a base's required statuses decide which of the controller's statuses are w const comment = commentFor(c, {}, ["mesh/repo-check"]); assert.ok(comment === null || !comment.includes("mesh/merge-gate"), comment ?? ""); }); + +test("a rule the forge gives with no contexts (null) requires nothing, and an unread rule is unknown", async () => { + const { requiredOf } = await import("../pulls.ts"); + // The forge's BranchProtection says status_check_contexts may be null (protection.ts); requiredOf takes it as it comes. + assert.deepEqual(requiredOf({ enable_status_check: true, status_check_contexts: null }), []); + assert.deepEqual(requiredOf({ enable_status_check: true, status_check_contexts: ["mesh/check", ""] }), ["mesh/check"]); + assert.deepEqual(requiredOf(null), []); + assert.equal(requiredOf(undefined), undefined); +}); diff --git a/modules/gitea/trunk.ts b/modules/gitea/trunk.ts index 40433b90..11100ca1 100644 --- a/modules/gitea/trunk.ts +++ b/modules/gitea/trunk.ts @@ -128,7 +128,7 @@ export interface TrunkForge { branchHead(owner: string, repo: string, branch: string): Promise; /** The rule the forge applies to a branch: which of the controller's statuses are kept there (issue 1301). Not given, * or not read: both, as before. */ - appliedProtection?(owner: string, repo: string, branch: string): Promise<{ enable_status_check?: boolean; status_check_contexts?: string[] } | null>; + appliedProtection?(owner: string, repo: string, branch: string): Promise<{ enable_status_check?: boolean; status_check_contexts?: string[] | null } | null>; } /** What it writes with: the merge check's one writer (gate.ts), which decides in the head's own turn. */