We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8a9f113 commit 6db99f1Copy full SHA for 6db99f1
.github/workflows/branch-cleanup.yml
@@ -0,0 +1,28 @@
1
+name: Branch Cleanup
2
+on:
3
+ pull_request:
4
+ types: [closed]
5
+ branches:
6
+ - main
7
+
8
+jobs:
9
+ delete-branch:
10
+ runs-on: ubuntu-latest
11
+ if: github.event.pull_request.merged == true && github.event.pull_request.head.ref != 'develop'
12
+ steps:
13
+ - name: Delete head branch
14
+ uses: actions/github-script@v7
15
+ with:
16
+ github-token: ${{ secrets.GITHUB_TOKEN }}
17
+ script: |
18
+ const branch = context.payload.pull_request.head.ref;
19
+ try {
20
+ await github.rest.git.deleteRef({
21
+ owner: context.repo.owner,
22
+ repo: context.repo.name,
23
+ ref: `heads/${branch}`
24
+ });
25
+ console.log(`Deleted branch ${branch}`);
26
+ } catch (error) {
27
+ console.error(`Error deleting branch ${branch}:`, error);
28
+ }
0 commit comments