-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.js
41 lines (35 loc) · 1.39 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
const core = require('@actions/core');
const github = require('@actions/github');
const { correctRecipients, correctMessage } = require('./utils');
async function run() {
try {
const issueNumber = github.context.payload.issue.number;
const owner = github.context.repo.owner;
const repo = github.context.repo.repo;
const label = github.context.payload.label.name;
// https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret
const token = core.getInput('token');
const octokit = github.getOctokit(token);
const labelRecipients = core.getInput('recipients').split("\n");
const match = labelRecipients.find((labelRecipient) => {
return labelRecipient.split("=")[0] === label;
});
const message = core.getInput('message');
if (match) {
const recipients = correctRecipients(match.split("=")[1]);
const comment = correctMessage(message, recipients, label);
const createCommentResponse = await octokit.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: comment
});
} else {
console.log("No matching recipients found for label ${label}.");
}
} catch (error) {
console.error(error);
core.setFailed(`The issue-label-notification-action action failed with ${error}`);
}
}
run();