Skip to content

Commit 6db99f1

Browse files
committed
feat(ci): add workflow to auto-delete merged branches
1 parent 8a9f113 commit 6db99f1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)