diff --git a/scripts/github/barnacle-auto-response.mjs b/scripts/github/barnacle-auto-response.mjs index 7d67b40b8c4..1381bd0b336 100644 --- a/scripts/github/barnacle-auto-response.mjs +++ b/scripts/github/barnacle-auto-response.mjs @@ -808,12 +808,12 @@ async function removeLabels(github, context, issueNumber, labels, labelSet) { issue_number: issueNumber, name: label, }); - labelSet.delete(label); } catch (error) { if (error?.status !== 404) { throw error; } } + labelSet.delete(label); } } diff --git a/test/scripts/barnacle-auto-response.test.ts b/test/scripts/barnacle-auto-response.test.ts index 94d884a31d8..860653425c1 100644 --- a/test/scripts/barnacle-auto-response.test.ts +++ b/test/scripts/barnacle-auto-response.test.ts @@ -105,11 +105,16 @@ function barnacleIssueContext( function barnacleGithub( files: ReturnType[], - options: { maintainerLogins?: string[]; repositoryRoles?: Record } = {}, + options: { + maintainerLogins?: string[]; + removeLabelNotFound?: string[]; + repositoryRoles?: Record; + } = {}, ) { const maintainerLogins = new Set( (options.maintainerLogins ?? []).map((login) => login.toLowerCase()), ); + const removeLabelNotFound = new Set(options.removeLabelNotFound ?? []); const repositoryRoles = Object.fromEntries( Object.entries(options.repositoryRoles ?? {}).map(([login, role]) => [ login.toLowerCase(), @@ -147,6 +152,11 @@ function barnacleGithub( }, removeLabel: async (params: { issue_number: number; name: string }) => { calls.removeLabel.push(params); + if (removeLabelNotFound.has(params.name)) { + const error = new Error("not found") as Error & { status: number }; + error.status = 404; + throw error; + } }, update: async (params: { issue_number: number; state?: string }) => { calls.update.push(params); @@ -516,6 +526,32 @@ describe("barnacle-auto-response", () => { expect(calls.update).toEqual([]); }); + it("does not close GitHub App-authored PRs when stale PR-limit label removal returns 404", async () => { + const { calls, github } = barnacleGithub([file("README.md")], { + removeLabelNotFound: ["r: too-many-prs"], + }); + + await runBarnacleAutoResponse({ + github, + context: barnacleContext( + { + user: { + login: "renovate[bot]", + type: "Bot", + }, + }, + ["r: too-many-prs"], + ), + core: { + info: () => undefined, + }, + }); + + expect(calls.removeLabel).toContainEqual(expect.objectContaining({ name: "r: too-many-prs" })); + expect(calls.createComment).toEqual([]); + expect(calls.update).toEqual([]); + }); + it("still adds candidate labels to broad contributor PRs", async () => { const { calls, github } = barnacleGithub([ file("ui/src/app.ts"),