From 9fdf53606ae47bf97a8d0de3bc7a7278a8f5395d Mon Sep 17 00:00:00 2001 From: RestartFU Date: Mon, 10 Nov 2025 09:35:02 -0500 Subject: [PATCH] feat: add github workflow to delete PR branch on merge --- .github/workflows/delete-branch-on-merge.yml | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/delete-branch-on-merge.yml diff --git a/.github/workflows/delete-branch-on-merge.yml b/.github/workflows/delete-branch-on-merge.yml new file mode 100644 index 0000000..50f6661 --- /dev/null +++ b/.github/workflows/delete-branch-on-merge.yml @@ -0,0 +1,32 @@ +name: Delete branch after PR merge + +on: + pull_request: + types: [closed] + +permissions: + contents: write # allows deleting refs (branches) + +jobs: + delete-branch: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + + steps: + - name: Delete branch + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: ${{ github.event.pull_request.head.ref }} + REPO: ${{ github.repository }} + PR_REPO: ${{ github.event.pull_request.head.repo.full_name }} + run: | + if [ "$PR_REPO" != "$REPO" ]; then + echo "Branch is from a fork ($PR_REPO) — skipping deletion." + exit 0 + fi + + echo "Deleting branch '$BRANCH' from '$REPO'..." + curl -s -X DELETE \ + -H "Authorization: Bearer $GH_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/$REPO/git/refs/heads/$BRANCH"