forked from bk-lopes/automatic-pull-request-review
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
35 lines (28 loc) · 854 Bytes
/
index.ts
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
import * as core from '@actions/core';
import * as github from '@actions/github';
const token = core.getInput('repo-token');
const requestEvent = core.getInput('event');
const body = core.getInput('body');
const octokit = github.getOctokit(token)
if (
(requestEvent === 'COMMENT' || requestEvent === 'REQUEST_CHANGES') &&
!body
) {
core.setFailed('Event type COMMENT & REQUEST_CHANGES require a body.');
}
const pullRequest = github.context.payload['pull_request'];
if (!pullRequest) {
core.setFailed('This action is meant to be ran on pull requests');
}
const query = `
mutation {
addPullRequestReview(input: {
pullRequestId: "${(<any>pullRequest)['node_id']}",
event: ${requestEvent},
body: "${body}"
}) {clientMutationId}
}`;
octokit.graphql(query).catch((err) => {
core.error(err);
core.setFailed(err.message);
});