-
Notifications
You must be signed in to change notification settings - Fork 0
/
close.js
38 lines (33 loc) · 1.22 KB
/
close.js
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
const github = require('@actions/github')
const core = require('@actions/core')
const context = github.context
const token = core.getInput('token')
const octokit = github.getOctokit(token)
const closeRegexp = /(?:(?:close|resolve)[ds]?|fix(?:e[ds])?) #(\d+)/gi
;(async function run() {
if (github.context.eventName === 'push') {
/** @type {import('@octokit/webhooks-definitions/schema').PushEvent} */
const payload = github.context.payload
for (const commit of payload.commits) {
if (!commit.distinct) continue
const taggedIssues = [...commit.message.matchAll(closeRegexp)].map(match => +match[1])
for (const issueNumber of taggedIssues) {
core.notice(`Closing issue #${issueNumber}`)
await octokit.rest.issues.update({
...context.repo,
issue_number: issueNumber,
state: 'closed',
}).catch(err => {
core.warning(`Issue #${issueNumber} - ${err.message}`)
})
await octokit.rest.issues.addAssignees({
...context.repo,
issue_number: issueNumber,
assignees: [commit.author.username]
}).catch(err => {
core.warning(`Issue #${issueNumber} - ${err.message}`)
})
}
}
}
})()