-
-
Notifications
You must be signed in to change notification settings - Fork 0
30 lines (27 loc) · 869 Bytes
/
Copy pathcleanup-branches.yml
File metadata and controls
30 lines (27 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
name: Cleanup Merged Branches
on:
pull_request:
types: [closed]
permissions: {}
jobs:
delete-branch:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/github-script@373c709c69115d41ff229c7e5df9f8788daa9553 # v9
with:
script: |
const branch = context.payload.pull_request.head.ref;
if (['master', 'main', 'next'].includes(branch)) return;
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branch}`,
});
console.log(`Deleted branch: ${branch}`);
} catch (e) {
console.log(`Branch ${branch} already deleted or protected`);
}