-
Notifications
You must be signed in to change notification settings - Fork 86
48 lines (44 loc) · 1.57 KB
/
close_issue.yaml
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
name: close-issues
# (c) 2020 by Linus Gasser for C4DT.org
# This action closes issues referenced in the PR in the case the merge
# does not happen on the 'default' branch.
# It searches for the same tags as the original github closers.
on:
pull_request:
types: [closed]
branches: [develop]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: script
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
if (!pr.merged){
console.log("Don't close issues when PR is not merged");
return;
}
const body = pr.body;
const lines = body.split('\n').map((l)=>l.trim());
const closers = new RegExp(
/^(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved) .*#/i);
const issues = lines.filter((l)=>l.match(closers));
const issue_nbrs = issues.map((i) => i.replace(/.*#/, ''));
issue_nbrs.forEach((i) => {
console.log("Closing issue " + i);
github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: i,
body: `Closed by PR #${pr.number} ${pr.title}`
});
github.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: i,
state: 'closed'
});
});