-
Notifications
You must be signed in to change notification settings - Fork 6
49 lines (46 loc) · 1.6 KB
/
issue-commit.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
name: Close Issue on Commit
on:
push:
branches:
- master
jobs:
close-issue:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Check commit messages for issue references
id: commit-check
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commits = await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
ref: process.env.GITHUB_SHA
});
for (const commit of commits.data) {
const match = commit.commit.message.match(/#(\d+)/);
if (match) {
console.log(`Found issue reference in commit: ${match[0]}`);
const issueNumber = parseInt(match[1]);
console.log(`Issue number: ${issueNumber}`);
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
if (issue.data.state !== 'closed') {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: "closed"
});
console.log(`Issue ${issueNumber} closed`);
} else {
console.log(`Issue ${issueNumber} is already closed`);
}
}
}