|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
3 |
| -const core = require('@actions/core'); |
4 |
| -const {context, GitHub} = require('@actions/github') |
| 3 | +const core = require("@actions/core"); |
| 4 | +const { context, GitHub } = require("@actions/github"); |
5 | 5 |
|
6 | 6 | async function run() {
|
7 |
| - const trigger = core.getInput('trigger'); |
| 7 | + const trigger = core.getInput("trigger"); |
8 | 8 | if (!trigger) {
|
9 |
| - core.setFailed('No `trigger` input given, aborting.') |
10 |
| - return |
| 9 | + core.setFailed("No `trigger` input given, aborting."); |
| 10 | + return; |
| 11 | + } |
| 12 | + const reaction = core.getInput("reaction"); |
| 13 | + const { GITHUB_TOKEN } = process.env; |
| 14 | + if (reaction && !GITHUB_TOKEN) { |
| 15 | + core.setFailed('If "reaction" is supplied, GITHUB_TOKEN is required'); |
| 16 | + return; |
11 | 17 | }
|
12 | 18 |
|
13 |
| - if (context.eventName === 'issue_comment' && !context.payload.issue.pull_request) { |
| 19 | + if ( |
| 20 | + context.eventName === "issue_comment" && |
| 21 | + !context.payload.issue.pull_request |
| 22 | + ) { |
14 | 23 | // not a pull-request comment, aborting
|
15 |
| - core.setOutput('triggered', 'false'); |
16 |
| - return |
| 24 | + core.setOutput("triggered", "false"); |
| 25 | + return; |
17 | 26 | }
|
18 | 27 |
|
19 |
| - const {owner, repo} = context.repo; |
| 28 | + const { owner, repo } = context.repo; |
20 | 29 |
|
21 |
| - const body = context.eventName === 'issue_comment' |
22 |
| - ? context.payload.comment.body |
23 |
| - : context.payload.pull_request.body; |
| 30 | + const body = |
| 31 | + context.eventName === "issue_comment" |
| 32 | + ? context.payload.comment.body |
| 33 | + : context.payload.pull_request.body; |
24 | 34 |
|
25 | 35 | if (!body.includes(trigger)) {
|
26 |
| - core.setOutput('triggered', 'false'); |
| 36 | + core.setOutput("triggered", "false"); |
27 | 37 | return;
|
28 | 38 | }
|
29 | 39 |
|
30 |
| - core.setOutput('triggered', 'true'); |
| 40 | + core.setOutput("triggered", "true"); |
31 | 41 |
|
32 |
| - const client = new GitHub(process.env.GITHUB_TOKEN); |
33 |
| - if (context.eventName === 'issue_comment') { |
| 42 | + if (!reaction) { |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + const client = new GitHub(GITHUB_TOKEN); |
| 47 | + if (context.eventName === "issue_comment") { |
34 | 48 | await client.reactions.createForIssueComment({
|
35 | 49 | owner,
|
36 | 50 | repo,
|
37 | 51 | comment_id: context.payload.comment.id,
|
38 |
| - content: 'rocket' |
39 |
| - }) |
| 52 | + content: reaction |
| 53 | + }); |
40 | 54 | } else {
|
41 | 55 | await client.reactions.createForIssue({
|
42 | 56 | owner,
|
43 | 57 | repo,
|
44 | 58 | issue_number: context.payload.pull_request.number,
|
45 |
| - content: 'rocket' |
| 59 | + content: reaction |
46 | 60 | });
|
47 | 61 | }
|
48 | 62 | }
|
49 | 63 |
|
50 | 64 | run().catch(err => {
|
51 |
| - console.error(err) |
52 |
| - core.setFailed('Unexpected error'); |
| 65 | + console.error(err); |
| 66 | + core.setFailed("Unexpected error"); |
53 | 67 | });
|
0 commit comments