Skip to content

Handle closed PR checkout failures as warnings instead of errors#14528

Merged
pelikhan merged 3 commits intomainfrom
copilot/handle-closed-pull-request-checkout
Feb 8, 2026
Merged

Handle closed PR checkout failures as warnings instead of errors#14528
pelikhan merged 3 commits intomainfrom
copilot/handle-closed-pull-request-checkout

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

When workflows process events on closed PRs (e.g., comments), checkout fails if the branch was deleted. This causes the entire workflow step to fail, preventing any further processing.

Changes

  • Detect closed PR state before checkout attempt via pullRequest.state === "closed"
  • Modified error handling in checkout_pr_branch.cjs to differentiate between closed and open PRs
  • Closed PRs: Log warnings, set checkout_pr_success=true, continue workflow
  • Open PRs: Preserve existing behavior - fail on checkout errors

Behavior

Closed PR with deleted branch:

⚠️ Closed PR Checkout Warning
  PR state: closed
  Checkout failed (expected for closed PR): branch not found
  Branch likely deleted: feature-branch
  This is expected behavior when a PR is closed

Step output: checkout_pr_success: "true" (workflow continues)

Open PR with checkout failure:

❌ Checkout Error Details
  Error message: network error

Step output: checkout_pr_success: "false" (workflow fails as before)

Original prompt

The JavaScript code that checks out a pull-request should handle the case where the pull-request is already closed. When it tries to check out the pull-request branch and the pull-request is closed, the branch has likely already been deleted.
If the pull-request is already closed and the checkout fails, this should not be treated as an error. It should be reported as a warning in the output, but it must not cause the step to fail.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 8, 2026 14:11
- Detect closed PR state before checkout
- Treat checkout failures on closed PRs as warnings, not errors
- Set checkout_pr_success to true for closed PRs
- Add comprehensive tests for closed PR scenarios
- Ensure open PRs still fail on checkout errors

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add handling for closed pull request during checkout Handle closed PR checkout failures as warnings instead of errors Feb 8, 2026
Copilot AI requested a review from pelikhan February 8, 2026 14:17
@pelikhan pelikhan marked this pull request as ready for review February 8, 2026 15:24
Copilot AI review requested due to automatic review settings February 8, 2026 15:24
@pelikhan pelikhan merged commit d968bd2 into main Feb 8, 2026
3 checks passed
@pelikhan pelikhan deleted the copilot/handle-closed-pull-request-checkout branch February 8, 2026 15:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the PR-branch checkout GitHub Action script to avoid failing workflows when processing events on closed pull requests whose branches may have been deleted, while preserving failure behavior for open PRs.

Changes:

  • Detects pullRequest.state === "closed" and treats checkout failures as warnings (step continues).
  • Adds step-summary + grouped warning logs for closed-PR checkout failures.
  • Extends unit tests to cover closed-PR warning behavior vs open-PR error behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
actions/setup/js/checkout_pr_branch.cjs Adds closed-PR detection and warning-only handling for checkout failures, including summary output.
actions/setup/js/checkout_pr_branch.test.cjs Adds test coverage for closed-PR checkout failures being warnings and open-PR failures remaining errors.
scratchpad/pr-checkout-logic-explained.md Documents the new closed-PR behavior and expected logs/tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


**This is not an error** - workflows targeting closed PRs will continue normally.`;

await core.summary.addRaw(warningMessage).write();
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the closed-PR warning path, core.summary.addRaw(...).write() is awaited without any protection. If writing the summary throws (filesystem issues, runner limitations, etc.), the script will throw and the step can still fail—negating the intent to treat closed-PR checkout failures as warnings. Consider wrapping the summary write in a try/catch (logging a warning on failure) so the closed-PR path cannot error out.

Suggested change
await core.summary.addRaw(warningMessage).write();
try {
await core.summary.addRaw(warningMessage).write();
} catch (summaryError) {
core.warning(`Failed to write closed PR summary: ${getErrorMessage(summaryError)}`);
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants