-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (53 loc) · 1.9 KB
/
close_PR_and_delete_branch.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
name: Close PR and delete branch
on:
issue_comment:
types: [created]
jobs:
CloseFinishedPR:
if: github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'auto-generated')
runs-on: ubuntu-latest
steps:
- name: Install jq
run: sudo apt-get install jq
- name: Checkout repository
uses: actions/checkout@v2
- name: Set env variables
run: |
echo "PR_DELETE=$(jq -r '.PR_DELETE' keywords.json)" >> $GITHUB_ENV
- name: Close PR
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prComment = context.payload.comment.body;
if (!prComment.includes(process.env.PR_DELETE)) {
console.log(`The PR comment does not contain the string "${process.env.PR_DELETE}".`);
return;
}
await github.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
state: 'closed'
});
- name: Delete branch
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prComment = context.payload.comment.body;
if (!prComment.includes(process.env.PR_DELETE)) {
console.log(`The PR comment does not contain the string "${process.env.PR_DELETE}".`);
return;
}
const pr = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const branchName = pr.data.head.ref;
await github.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'heads/' + branchName
});