-
Notifications
You must be signed in to change notification settings - Fork 0
37 lines (33 loc) · 1.04 KB
/
copier-delete-branch.yaml
File metadata and controls
37 lines (33 loc) · 1.04 KB
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
name: Copier PR Clean
on:
pull_request:
types: [closed]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
copier-delete-branch:
name: Copier delete branch
runs-on: ['ubuntu-latest']
permissions:
contents: write
steps:
- name: Delete branch via GitHub API
uses: actions/github-script@v9
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const fullRef = 'refs/heads/copier/update';
const branchRef = fullRef.replace(/^refs\//, '');
try {
await github.rest.git.deleteRef({ owner, repo, ref: branchRef });
console.log(`Deleted branch ${branchRef}`);
} catch (error) {
if (error.status === 422 || error.status === 404) {
console.log(`Branch ${branchRef} does not exist or already deleted.`);
} else {
throw error;
}
}