-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
42 lines (38 loc) · 1.28 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
const core = require("@actions/core");
const github = require("@actions/github");
try {
const github_token = core.getInput("GITHUB_TOKEN");
const requiredLabels = core.getInput("labels").split(",");
const labelsInIssue = github.context.payload.issue.labels.map((label) => {
return label.name;
});
const octokit = github.getOctokit(github_token);
const missingLabels = requiredLabels.filter((requiredLabel) => {
return !labelsInIssue.includes(requiredLabel);
});
const missingLabelsString = missingLabels.join(", ");
const message =
"The following label **" +
missingLabelsString +
"** does not exist on the issue. Please add these labels to avoid any inconvenience in future.";
if (labelsInIssue.length === 0) {
octokit.rest.issues.createComment({
issue_number: github.context.issue.number,
owner: github.context.repo.owner,
repo: github.context.repo.repo,
body: message,
});
} else if (
missingLabels.length === requiredLabels.length &&
missingLabels.length > 0
) {
octokit.rest.issues.createComment({
issue_number: github.context.issue.number,
owner: github.context.repo.owner,
repo: github.context.repo.repo,
body: message,
});
}
} catch (error) {
core.setFailed(error.message);
}