Repository navigation
[build] delete a PR's head branch when the PR is closed without merging - #18199
titusfortner wants to merge 1 commit into
Conversation
|
/agentic_describe |
|
/agentic_review |
PR Summary by QodoDelete unmerged PR head branches when PRs close
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
PR Summary by QodoDelete same-repository branches when PRs close without merging
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1. New work on closed branches gets deleted
|
| GH_TOKEN: ${{ github.token }} | ||
| REPO: ${{ github.repository }} | ||
| BRANCH: ${{ github.event.pull_request.head.ref }} | ||
| run: gh api --method DELETE "repos/$REPO/git/refs/heads/$BRANCH" |
There was a problem hiding this comment.
1. New work on closed branches gets deleted 🐞 Bug ☼ Reliability
The gh api step deletes the ref named in the close event without checking whether it still points to pull_request.head.sha. If an update workflow reuses one of its fixed branch names while this job is queued, the job can delete the newly pushed branch, including one already used for a new pull request.
Agent Prompt
## Issue description
The close-event job can delete a branch that was updated or recreated after the pull request closed.
## Fix Focus Areas
- .github/workflows/delete-closed-branch.yml[20-25]
## Recommended Fix
Before deletion, fetch the current head ref and skip cleanup unless its SHA matches the closed pull request's head SHA. Also skip deletion if another open pull request uses that ref; handle an already-deleted ref as successful cleanup.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
💥 What does this PR do?
🔧 Implementation Notes
pull_request_targetbecausepull_requestdoesn't run for PRs with merge conflicts, which most abandoned PRs have; it never checks out PR code, and the branch name reaches the shell only through an env var.🤖 AI assistance
💡 Additional Considerations
🔄 Types of changes