File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Delete branch after PR merge
2+
3+ on :
4+ pull_request :
5+ types : [closed]
6+
7+ permissions :
8+ contents : write # allows deleting refs (branches)
9+
10+ jobs :
11+ delete-branch :
12+ if : github.event.pull_request.merged == true
13+ runs-on : ubuntu-latest
14+
15+ steps :
16+ - name : Delete branch
17+ env :
18+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
19+ BRANCH : ${{ github.event.pull_request.head.ref }}
20+ REPO : ${{ github.repository }}
21+ PR_REPO : ${{ github.event.pull_request.head.repo.full_name }}
22+ run : |
23+ if [ "$PR_REPO" != "$REPO" ]; then
24+ echo "Branch is from a fork ($PR_REPO) — skipping deletion."
25+ exit 0
26+ fi
27+
28+ echo "Deleting branch '$BRANCH' from '$REPO'..."
29+ curl -s -X DELETE \
30+ -H "Authorization: Bearer $GH_TOKEN" \
31+ -H "Accept: application/vnd.github.v3+json" \
32+ "https://api.github.com/repos/$REPO/git/refs/heads/$BRANCH"
You can’t perform that action at this time.
0 commit comments