File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11name : Delete merged branch
22
33on :
4- pull_request :
5- types :
6- - closed
4+ push :
5+ branches :
6+ - main
7+
8+ permissions :
9+ contents : write
710
811jobs :
9- delete-branch :
10- if : github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
12+ delete-merged-branch :
1113 runs-on : ubuntu-latest
1214 steps :
15+ - name : Checkout repo
16+ uses : actions/checkout@v4
17+
18+ - name : Get merged PR
19+ id : pr
20+ uses : octokit/request-action@v2.x
21+ with :
22+ route : GET /repos/${{ github.repository }}/commits/${{ github.sha }}/pulls
23+ env :
24+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
25+
1326 - name : Delete merged branch
27+ if : steps.pr.outputs.data != '[]'
1428 run : |
15- branch="$ {{ github.event.pull_request.head.ref }}"
29+ branch=$(echo '$ {{ steps.pr.outputs.data }}' | jq -r '.[0].head.ref')
1630 repo="${{ github.repository }}"
1731 token="${{ secrets.GITHUB_TOKEN }}"
32+
33+ echo "Deleting branch: $branch"
1834 if [[ "$branch" != "main" && "$branch" != "master" ]]; then
1935 curl -s -X DELETE \
2036 -H "Authorization: Bearer $token" \
You can’t perform that action at this time.
0 commit comments