-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
108 lines (87 loc) · 2.78 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const core = require("@actions/core");
const github = require("@actions/github");
const TASK_LIST_ITEM = /(?:^|\n)\s*-\s+\[([ xX])\]\s+((?!~).*)/g;
const COMMENT_START = "<!--";
const COMMENT_END = "-->";
async function action() {
const bodyList = [];
const token = core.getInput("token");
const octokit = github.getOctokit(token);
const skipRegexPattern = core.getInput("skipDescriptionRegex");
const skipRegexFlags = core.getInput("skipDescriptionRegexFlags");
const skipDescriptionRegex = !!skipRegexPattern ? new RegExp(skipRegexPattern, skipRegexFlags) : false;
const issueNumber =
core.getInput("issueNumber") || github.context.issue?.number;
core.debug(`issue number: ${issueNumber}`);
if (!issueNumber) {
core.setFailed("Could not determine issue number");
return;
}
const { data: issue } = await octokit.rest.issues.get({
...github.context.repo,
issue_number: issueNumber,
});
if (issue.body) {
bodyList.push(issue.body);
}
if (core.getInput("skipComments") != "true") {
const { data: comments } = await octokit.rest.issues.listComments({
...github.context.repo,
issue_number: issueNumber,
});
for (let comment of comments) {
bodyList.push(comment.body);
}
}
// Check each comment for a checklist
let containsChecklist = false;
let openComment = false;
var incompleteItems = [];
for (let body of bodyList) {
// Break in to lines to do comment detection
for (let line of body.split("\n")) {
if (line.includes(COMMENT_START)) {
openComment = true;
}
if (line.includes(COMMENT_END)) {
openComment = false;
}
if (!openComment) {
var matches = [...line.matchAll(TASK_LIST_ITEM)];
for (let item of matches) {
var is_complete = item[1] != " ";
if(skipRegexPattern && skipDescriptionRegex.test(item[2])) {
console.log("Skipping task list item: " + item[2]);
continue;
}
containsChecklist = true;
if (is_complete) {
console.log("Completed task list item: " + item[2]);
} else {
console.log("Incomplete task list item: " + item[2]);
incompleteItems.push(item[2]);
}
}
}
}
}
if (incompleteItems.length > 0) {
core.setFailed(
"The following items are not marked as completed: " +
incompleteItems.join(", ")
);
return;
}
const requireChecklist = core.getInput("requireChecklist");
if (requireChecklist != "false" && !containsChecklist) {
core.setFailed(
"No task list was present and requireChecklist is turned on"
);
return;
}
console.log("There are no incomplete task list items");
}
if (require.main === module) {
action();
}
module.exports = action;