-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (55 loc) · 1.58 KB
/
delete_pr_branches.yml
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: 'Delete PR branches'
on:
pull_request:
types:
- closed
jobs:
delete_pr_branches:
name: 'Delete PR branches'
if: startsWith(github.head_ref, 'pr/')
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- name: 'Delete PR head branch'
uses: actions/github-script@v6
env:
HEAD_REF: ${{ github.head_ref }}
with:
script: |
const { repo, owner } = context.repo;
try {
await github.rest.git.deleteRef({
owner: owner,
repo: repo,
ref: `heads/${process.env.HEAD_REF}`,
});
} catch (e) {
console.warn(e);
}
- name: 'Delete PR other head branches'
if: ${{ endsWith(github.head_ref, '/all') && github.event.pull_request.merged }}
uses: actions/github-script@v6
env:
BASE_REF: ${{ github.base_ref }}
with:
script: |
const { repo, owner } = context.repo;
const pulls = await github.rest.pulls.list({
owner: owner,
repo: repo,
base: process.env.BASE_REF,
state: 'open',
});
for (const pr of pulls.data) {
try {
await github.rest.git.deleteRef({
owner: owner,
repo: repo,
ref: `heads/${pr.head.ref}`,
});
} catch (e) {
console.warn(e);
}
}