ci: auto-delete PR head branch on close#105
Merged
Merged
Conversation
GitHub's repo-level "automatically delete head branches" is off, so merged branches linger (e.g. jeanextreme002/* and ci/* from recent PRs). This workflow deletes the head ref when a PR from this repo is merged, skipping protected branches (main, gh-pages) and PRs from forks.
Drop the merged==true guard so abandoned PRs also get their head branch cleaned up. Rename the workflow file/name to match the broader scope.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.github/workflows/delete-pr-branch.ymlto delete a PR's head branch automatically whenever the PR is closed (merged or abandoned).main,gh-pages) and PRs from forks (where we can't delete refs anyway).Motivation: repo currently has
deleteBranchOnMerge: false, so merged branches stick around (e.g.jeanextreme002/*andci/*from recent PRs are still on the remote). This also cleans up branches from PRs that get closed without merging, which the repo-level setting wouldn't cover.Alternative — and complementary — fix: flip on Settings → General → Automatically delete head branches in the repo UI. The workflow still adds value because (a) it also handles closed-without-merge and (b) it keeps cleanup behavior in version control.
Test plan
ci/delete-branch-on-mergehead branch is deleted automatically by the new workflow run.mainfrom a fork is a no-op (guarded by thehead.repo.full_name == github.repositorycheck).