-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (24 loc) · 874 Bytes
/
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
const core = require("@actions/core");
const github = require("@actions/github");
const { Octokit } = require("@octokit/rest");
async function run() {
try {
const pullRequestNumber = github.context.payload.number;
const author = github.context.payload.sender.login
const token = core.getInput("github-token");
let reviewers = JSON.parse(core.getInput("reviewers"));
const octokit = new Octokit({auth:token})
reviewers = reviewers.filter(r=>r!==author)
const reviewer = reviewers[Math.floor(Math.random() * reviewers.length)];
await octokit.pulls.requestReviewers({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: pullRequestNumber,
reviewers: [reviewer],
});
core.setOutput("reviewer", reviewer);
} catch (error) {
core.setFailed(error.message);
}
}
run();