From 1f69546e22a510d0607f38717d94c74868ae6c61 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 15:30:40 +0000 Subject: [PATCH 1/3] Initial plan From b6059730b64287794f2a6a2dbf848194d590f357 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 15:36:46 +0000 Subject: [PATCH 2/3] Add step summary message when PR checkout fails Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- actions/setup/js/checkout_pr_branch.cjs | 28 +++++++++++++++++++- actions/setup/js/checkout_pr_branch.test.cjs | 27 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/actions/setup/js/checkout_pr_branch.cjs b/actions/setup/js/checkout_pr_branch.cjs index dadf69ad85..e2225694d9 100644 --- a/actions/setup/js/checkout_pr_branch.cjs +++ b/actions/setup/js/checkout_pr_branch.cjs @@ -40,7 +40,33 @@ async function main() { core.info(`✅ Successfully checked out PR #${prNumber}`); } } catch (error) { - core.setFailed(`Failed to checkout PR branch: ${getErrorMessage(error)}`); + const errorMsg = getErrorMessage(error); + + // Write to step summary to provide context about the failure + const summaryContent = `## ❌ Failed to Checkout PR Branch + +**Error:** ${errorMsg} + +### Possible Reasons + +This failure typically occurs when: +- The pull request has been closed or merged +- The branch has been deleted +- There are insufficient permissions to access the PR + +### What to Do + +If the pull request is closed, you may need to: +1. Reopen the pull request, or +2. Create a new pull request with the changes + +If the pull request is still open, verify that: +- The branch still exists in the repository +- You have the necessary permissions to access it +`; + + await core.summary.addRaw(summaryContent).write(); + core.setFailed(`Failed to checkout PR branch: ${errorMsg}`); } } diff --git a/actions/setup/js/checkout_pr_branch.test.cjs b/actions/setup/js/checkout_pr_branch.test.cjs index af9958e4fc..df0be0015a 100644 --- a/actions/setup/js/checkout_pr_branch.test.cjs +++ b/actions/setup/js/checkout_pr_branch.test.cjs @@ -10,6 +10,10 @@ describe("checkout_pr_branch.cjs", () => { mockCore = { info: vi.fn(), setFailed: vi.fn(), + summary: { + addRaw: vi.fn().mockReturnThis(), + write: vi.fn().mockResolvedValue(undefined), + }, }; // Mock exec @@ -92,6 +96,14 @@ describe("checkout_pr_branch.cjs", () => { await runScript(); + expect(mockCore.summary.addRaw).toHaveBeenCalled(); + expect(mockCore.summary.write).toHaveBeenCalled(); + + const summaryCall = mockCore.summary.addRaw.mock.calls[0][0]; + expect(summaryCall).toContain("Failed to Checkout PR Branch"); + expect(summaryCall).toContain("git fetch failed"); + expect(summaryCall).toContain("pull request has been closed"); + expect(mockCore.setFailed).toHaveBeenCalledWith("Failed to checkout PR branch: git fetch failed"); }); @@ -101,6 +113,13 @@ describe("checkout_pr_branch.cjs", () => { await runScript(); + expect(mockCore.summary.addRaw).toHaveBeenCalled(); + expect(mockCore.summary.write).toHaveBeenCalled(); + + const summaryCall = mockCore.summary.addRaw.mock.calls[0][0]; + expect(summaryCall).toContain("Failed to Checkout PR Branch"); + expect(summaryCall).toContain("git checkout failed"); + expect(mockCore.setFailed).toHaveBeenCalledWith("Failed to checkout PR branch: git checkout failed"); }); }); @@ -129,6 +148,14 @@ describe("checkout_pr_branch.cjs", () => { await runScript(); + expect(mockCore.summary.addRaw).toHaveBeenCalled(); + expect(mockCore.summary.write).toHaveBeenCalled(); + + const summaryCall = mockCore.summary.addRaw.mock.calls[0][0]; + expect(summaryCall).toContain("Failed to Checkout PR Branch"); + expect(summaryCall).toContain("gh pr checkout failed"); + expect(summaryCall).toContain("pull request has been closed"); + expect(mockCore.setFailed).toHaveBeenCalledWith("Failed to checkout PR branch: gh pr checkout failed"); }); From 82eac8d03b3ffc8f4db0931a593ba54f3f0cb39f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Feb 2026 15:52:10 +0000 Subject: [PATCH 3/3] Move PR checkout failure message to markdown template Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- actions/setup/js/checkout_pr_branch.cjs | 30 ++++---------- actions/setup/js/checkout_pr_branch.test.cjs | 41 ++++++++++++++++++++ actions/setup/md/pr_checkout_failure.md | 20 ++++++++++ 3 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 actions/setup/md/pr_checkout_failure.md diff --git a/actions/setup/js/checkout_pr_branch.cjs b/actions/setup/js/checkout_pr_branch.cjs index e2225694d9..a3310b3568 100644 --- a/actions/setup/js/checkout_pr_branch.cjs +++ b/actions/setup/js/checkout_pr_branch.cjs @@ -7,6 +7,8 @@ */ const { getErrorMessage } = require("./error_helpers.cjs"); +const { renderTemplate } = require("./messages_core.cjs"); +const fs = require("fs"); async function main() { const eventName = context.eventName; @@ -42,28 +44,12 @@ async function main() { } catch (error) { const errorMsg = getErrorMessage(error); - // Write to step summary to provide context about the failure - const summaryContent = `## ❌ Failed to Checkout PR Branch - -**Error:** ${errorMsg} - -### Possible Reasons - -This failure typically occurs when: -- The pull request has been closed or merged -- The branch has been deleted -- There are insufficient permissions to access the PR - -### What to Do - -If the pull request is closed, you may need to: -1. Reopen the pull request, or -2. Create a new pull request with the changes - -If the pull request is still open, verify that: -- The branch still exists in the repository -- You have the necessary permissions to access it -`; + // Load and render step summary template + const templatePath = "/opt/gh-aw/prompts/pr_checkout_failure.md"; + const template = fs.readFileSync(templatePath, "utf8"); + const summaryContent = renderTemplate(template, { + error_message: errorMsg, + }); await core.summary.addRaw(summaryContent).write(); core.setFailed(`Failed to checkout PR branch: ${errorMsg}`); diff --git a/actions/setup/js/checkout_pr_branch.test.cjs b/actions/setup/js/checkout_pr_branch.test.cjs index df0be0015a..c4deb67c05 100644 --- a/actions/setup/js/checkout_pr_branch.test.cjs +++ b/actions/setup/js/checkout_pr_branch.test.cjs @@ -62,6 +62,47 @@ describe("checkout_pr_branch.cjs", () => { if (module === "./error_helpers.cjs") { return { getErrorMessage: error => (error instanceof Error ? error.message : String(error)) }; } + if (module === "./messages_core.cjs") { + return { + renderTemplate: (template, context) => { + return template.replace(/\{(\w+)\}/g, (match, key) => { + const value = context[key]; + return value !== undefined && value !== null ? String(value) : match; + }); + }, + }; + } + if (module === "fs") { + return { + readFileSync: (path, encoding) => { + // Return mock template for pr_checkout_failure.md + if (path.includes("pr_checkout_failure.md")) { + return `## ❌ Failed to Checkout PR Branch + +**Error:** {error_message} + +### Possible Reasons + +This failure typically occurs when: +- The pull request has been closed or merged +- The branch has been deleted +- There are insufficient permissions to access the PR + +### What to Do + +If the pull request is closed, you may need to: +1. Reopen the pull request, or +2. Create a new pull request with the changes + +If the pull request is still open, verify that: +- The branch still exists in the repository +- You have the necessary permissions to access it +`; + } + throw new Error(`Unexpected file read: ${path}`); + }, + }; + } throw new Error(`Module ${module} not mocked in test`); }; diff --git a/actions/setup/md/pr_checkout_failure.md b/actions/setup/md/pr_checkout_failure.md new file mode 100644 index 0000000000..a0eb122f69 --- /dev/null +++ b/actions/setup/md/pr_checkout_failure.md @@ -0,0 +1,20 @@ +## ❌ Failed to Checkout PR Branch + +**Error:** {error_message} + +### Possible Reasons + +This failure typically occurs when: +- The pull request has been closed or merged +- The branch has been deleted +- There are insufficient permissions to access the PR + +### What to Do + +If the pull request is closed, you may need to: +1. Reopen the pull request, or +2. Create a new pull request with the changes + +If the pull request is still open, verify that: +- The branch still exists in the repository +- You have the necessary permissions to access it