-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
77 lines (70 loc) · 2.16 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import fetch from 'node-fetch';
import { getInput, setFailed } from '@actions/core';
import { context } from '@actions/github';
import { Octokit } from '@octokit/core';
import * as core from '@actions/core';
async function run() {
try {
const githubToken = getInput('github-token');
const octokit = new Octokit({ auth: githubToken });
const comment = context.payload.comment || context.payload.review;
if (!comment) {
core.debug('No comment or review body found.');
return;
}
if (!(comment.body || '').toLowerCase().match(/lgtm/)) {
core.debug('nothing to do.');
return;
}
switch (context.eventName) {
case 'issue_comment':
break;
case 'pull_request_review':
if (context.payload.review.state !== 'approved') {
core.debug('nothing to do.');
return;
}
break;
case 'pull_request_review_comment':
break;
default:
core.debug('nothing to do.');
return;
}
fetch('https://lgtmoon.herokuapp.com/api/images/random')
.then(response => {
return response.json();
})
.then(data => {
const imageUrl = data.images[0].url;
if (
context.eventName === 'issue_comment' ||
context.eventName === 'pull_request_review'
) {
octokit.request(
'POST /repos/{owner}/{repo}/issues/{issue_number}/comments',
{
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: ``,
},
);
} else if (context.eventName === 'pull_request_review_comment') {
octokit.request(
'POST /repos/{owner}/{repo}/pulls/{pull_number}/comments/{comment_id}/replies',
{
owner: context.repo.owner,
repo: context.repo.repo,
body: ``,
pull_number: context.payload.pull_request.number,
comment_id: context.payload.comment.id,
},
);
}
});
} catch (error) {
setFailed(error.message);
}
}
run();