-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
62 lines (48 loc) · 2.01 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
import { getInput, setFailed } from '@actions/core';
import { getOctokit, context } from '@actions/github';
import getPullRequest from './lib/get-pull-request.js';
import { signiture } from './lib/constants.js';
const allowedEvents = ['pull_request', 'pull_request_target']
if(!allowedEvents.includes(context.eventName)) {
console.log(`continue-on-error-comment is designed to be used with pull request and does not work with a [${context.eventName}] event. We are ignoring this event.`);
} else {
try {
const myToken = getInput('repo-token', { required: true });
const outcome = getInput('outcome', { required: true });
const testId = getInput('test-id', { required: true });
const botUser = getInput('bot-user', { required: true });
if (outcome === 'failure') {
const octokit = getOctokit(myToken);
const pullRequest = await getPullRequest(context, octokit);
const { data: comments } = await octokit.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequest.number,
});
const existingComment = comments.find((comment) => comment.user.login === botUser && comment.body.endsWith(signiture) && comment.body.includes(`sha: ${context.sha}`));
if (existingComment) {
let body = existingComment.body.split('\n');
body.splice(body.length - 3, 0, `- ${testId}`);
await octokit.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: body.join('\n'),
});
} else {
const body = `Some tests with 'continue-on-error: true' have failed:
- ${testId}
<!-- sha: ${context.sha} -->
${signiture}`;
await octokit.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequest.number,
body,
});
}
}
} catch (error) {
setFailed(error.message);
}
}