-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
34 lines (29 loc) · 1.18 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
const core = require('@actions/core');
const github = require('@actions/github');
async function run() {
try {
let requiredReviews = [];
const team = JSON.parse(core.getInput('team'));
const githubToken = core.getInput('GITHUB_TOKEN');
const octokit = github.getOctokit(githubToken);
const creator = (await octokit.pulls.get({
owner: github.context.payload.pull_request.base.repo.owner.login,
repo: github.context.payload.pull_request.base.repo.name,
pull_number: github.context.payload.pull_request.number,
})).data.user.login;
const reviews = (await octokit.pulls.listReviews({
owner: github.context.payload.pull_request.base.repo.owner.login,
repo: github.context.payload.pull_request.base.repo.name,
pull_number: github.context.payload.pull_request.number,
})).data.map((review) => review.user.login);
team.forEach(member => {
requiredReviews.push(reviews.includes(member));
});
if(!team.includes(creator) && !requiredReviews.includes(true)) {
core.setFailed(`Expect at leat one review from the team: ${JSON.stringify(team)}`);
}
} catch (error) {
core.setFailed(error.message);
}
}
run();