-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
68 lines (58 loc) · 1.9 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
import * as core from '@actions/core';
import * as github from '@actions/github';
import { normalMode, recreateMode, appendMode, deleteMode } from './modes';
import { getCommenter } from './comment/commenter';
(async () => {
try {
const repository = core.getInput('repository');
const [owner, repo] = repository.split('/');
if (!owner || !repo) {
throw new Error(`Invalid repository: ${repository}`);
}
const number = core.getInput('number');
const commitSHA = core.getInput('commit-sha');
const identifier = core.getInput('id');
const appendComment = core.getInput('append');
const recreateComment = core.getInput('recreate');
const deleteComment = core.getInput('delete');
const fail = core.getInput('fail');
const githubToken = core.getInput('github-token');
const message = core.getInput('message');
const octokit = github.getOctokit(githubToken);
let commenter;
try {
commenter = getCommenter(octokit, {
owner,
repo,
number,
commitSHA,
});
} catch (err) {
core.setFailed(err);
return;
}
let mode = normalMode;
if (appendComment === 'true' && recreateComment === 'true') {
core.setFailed('Not allowed to set both `append` and `recreate` to true.');
return;
}
if (deleteComment === 'true' && (appendComment === 'true' || recreateComment === 'true')) {
core.setFailed('Not allowed to set `delete` to true with `append` or `recreate`.');
return;
}
if (recreateComment === 'true') {
mode = recreateMode;
} else if (appendComment === 'true') {
mode = appendMode;
} else if (deleteComment === 'true') {
mode = deleteMode;
}
await mode(commenter, identifier, message);
if (fail === 'true') {
core.setFailed(message);
}
} catch (error) {
console.error(error);
core.setFailed(error.message);
}
})();