forked from AveryCameronUofR/add-reviewer-gh-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (38 loc) · 1.14 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
const core = require("@actions/core");
const github = require("@actions/github");
/**
* Adds reviewers to a pull request.
*
* Uses octokit to access GitHub Actions information to add a reviewer
* or list of reviewers to the pull request the action executed on.
*
* @since 1.0.0
*/
function run() {
try {
const reviewers = core.getInput("reviewers");
const removeRequest = core.getInput("remove").toLowerCase() === "true";
const prReviewers = reviewers.split(", ");
const token = process.env["GITHUB_TOKEN"] || core.getInput("token");
const octokit = new github.getOctokit(token);
const context = github.context;
if (context.payload.pull_request == null) {
core.setFailed("No pull request found.");
return;
}
const pullRequestNumber = context.payload.pull_request.number;
const params = {
...context.repo,
pull_number: pullRequestNumber,
reviewers: prReviewers,
};
if (removeRequest) {
octokit.pulls.removeRequestedReviewers(params);
} else {
octokit.pulls.requestReviewers(params);
}
} catch (error) {
core.setFailed(error.message);
}
}
run();