-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (49 loc) · 1.62 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
44
45
46
47
48
49
50
51
52
53
54
55
56
const core = require('@actions/core');
const github = require('@actions/github');
const fetch = require('node-fetch');
try {
const token = core.getInput('GITHUB_TOKEN', {required: true});
const event = core.getInput('EVENT_TYPE', {required: true});
const message = core.getInput('MESSAGE');
const pullRequest = github.context.payload.pull_request
const prNumber = pullRequest.number
if (!pullRequest) {
core.setFailed('🐢 This action isn\'t pull requests. Please run this action on: pull_request');
process.exit(1);
}
if (!['COMMENT','REQUEST_CHANGES'].includes(event) && !message) {
core.setFailed('🐢 EVENT_TYPE is a COMMENT or REQUEST_CHANGES required a MESSAGE.');
process.exit(1);
}
pullRequestReview({
token,
prNumber,
message,
event,
});
} catch(e) {
core.error(e);
core.setFailed(e.message);
}
function pullRequestReview({token, prNumber, message, event}) {
console.log("You can join to our server https://discord.gg/fV8EgwSpgN")
fetch(`https://api.github.com/repos/${github.context.repo.owner}/${github.context.repo.repo}/pulls/${prNumber}/reviews`, {
method: 'post',
body: JSON.stringify({
body: message,
event: event,
}),
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `Token ${token}`,
'Content-Type': 'application/json'
},
})
.then(() => {
core.info(`Done. PR #${prNumber} 🎉`)
})
.catch((err) => {
core.error(err)
core.setFailed(err.message)
})
}