-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (44 loc) · 1.43 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const core = require("@actions/core");
const github = require("@actions/github");
(async () => {
const client = core.getInput("github-token", { required: true });
const { issue } = github.context;
const closedIssueLabel = core.getInput("closed-issues-label");
const closedIssueComment = core.getInput("closed-issues-comment");
const expirationDate = Date.parse(core.getInput("expiration-date"));
const octokit = github.getOctokit(client);
const issueData = await octokit.issues.get({
owner: issue.owner,
repo: issue.repo,
issue_number: issue.number
});
const issueCreatedAt = Date.parse(issueData.data.created_at.substring(0,10));
//Close the issue if it was created after the expiration date
if(issueCreatedAt > expirationDate){
//Add a label to de issue, if there is one
if (closedIssueLabel) {
await octokit.issues.addLabels({
owner: issue.owner,
repo: issue.repo,
issue_number: issue.number,
labels: [closedIssueLabel]
});
}
//Add a comment to de issue, if there is one
if(closedIssueComment){
await octokit.issues.createComment({
owner: issue.owner,
repo: issue.repo,
issue_number: issue.number,
body: closedIssueComment
});
}
//Close the issue
await octokit.issues.update({
owner: issue.owner,
repo: issue.repo,
issue_number: issue.number,
state: "closed"
});
}
})();