From f3475869e9d9d34a8360fe2db6f32c05106726c7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 19 Jun 2026 05:36:48 +0000 Subject: [PATCH] jsweep: clean update_pull_request_branches.cjs - Replace indexed for-loop with for...of entries() in main() - Add 4 new test cases (17 total, up from 13): - Skips closed pull requests - Skips PRs with mergeable: null (pending computation) - Does not treat non-object errors as non-fatal - Does not treat 404 status errors as non-fatal Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../setup/js/update_pull_request_branches.cjs | 3 +- .../js/update_pull_request_branches.test.cjs | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/actions/setup/js/update_pull_request_branches.cjs b/actions/setup/js/update_pull_request_branches.cjs index 92e6cd41af0..c58f5175a30 100644 --- a/actions/setup/js/update_pull_request_branches.cjs +++ b/actions/setup/js/update_pull_request_branches.cjs @@ -150,11 +150,10 @@ async function main() { let skippedCount = 0; let failedCount = 0; - for (let i = 0; i < mergeablePullRequests.length; i++) { + for (const [i, pullNumber] of mergeablePullRequests.entries()) { if (i > 0) { await sleep(UPDATE_DELAY_MS); } - const pullNumber = mergeablePullRequests[i]; try { core.info(`Updating branch for PR #${pullNumber}`); await updatePullRequestBranch(owner, repo, pullNumber); diff --git a/actions/setup/js/update_pull_request_branches.test.cjs b/actions/setup/js/update_pull_request_branches.test.cjs index 3d994aab03c..8199e3542e8 100644 --- a/actions/setup/js/update_pull_request_branches.test.cjs +++ b/actions/setup/js/update_pull_request_branches.test.cjs @@ -207,6 +207,40 @@ describe("update_pull_request_branches", () => { expect(moduleUnderTest.isNonFatalUpdateBranchError(new Error("Something else went wrong"))).toBe(false); }); + it("skips closed pull requests when filtering mergeable pull requests", async () => { + mockGithub.rest.pulls.get.mockImplementation(async ({ pull_number }) => { + if (pull_number === 1) return { data: { state: "closed", mergeable: true, draft: false, head: { repo: { full_name: "owner/repo" } } } }; + return { data: { state: "open", mergeable: true, draft: false, head: { repo: { full_name: "owner/repo" } } } }; + }); + + const result = await moduleUnderTest.filterMergeablePullRequests("owner", "repo", [1, 2]); + + expect(result).toEqual([2]); + expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("Skipping PR #1")); + }); + + it("skips pull requests where mergeable is null (GitHub pending computation)", async () => { + mockGithub.rest.pulls.get.mockResolvedValue({ + data: { state: "open", mergeable: null, draft: false, head: { repo: { full_name: "owner/repo" } } }, + }); + + const result = await moduleUnderTest.filterMergeablePullRequests("owner", "repo", [5]); + + expect(result).toEqual([]); + expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("mergeable=null")); + }); + + it("does not treat non-object errors as non-fatal", () => { + expect(moduleUnderTest.isNonFatalUpdateBranchError("some string error")).toBe(false); + expect(moduleUnderTest.isNonFatalUpdateBranchError(null)).toBe(false); + expect(moduleUnderTest.isNonFatalUpdateBranchError(42)).toBe(false); + }); + + it("does not treat 404 status errors as non-fatal", () => { + const err = Object.assign(new Error("Not Found"), { status: 404 }); + expect(moduleUnderTest.isNonFatalUpdateBranchError(err)).toBe(false); + }); + it("filters out non-integer pull request numbers", async () => { mockGithub.paginate.mockResolvedValue([{ number: 1 }, { number: "bad" }, { number: null }, { number: 2 }]); mockGithub.rest.pulls.get.mockResolvedValue({