forked from Dev-Card/DevCard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommentResults.js
More file actions
98 lines (83 loc) · 2.11 KB
/
Copy pathcommentResults.js
File metadata and controls
98 lines (83 loc) · 2.11 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module.exports = async ({
github,
context,
backend,
mobile,
web,
backendLint,
backendTest,
backendTypecheck,
mobileLint,
mobileTest,
webBuild,
backendLintOutput,
mobileLintOutput,
}) => {
const owner = context.repo.owner;
const repo = context.repo.repo;
const prNumber = context.payload.pull_request.number;
const status = (s) => {
if (s === 'success') return 'PASS';
if (s === 'failure') return 'FAIL';
if (s === 'skipped') return 'SKIP';
return '-';
};
const lintDetails = (output) => {
if (!output || !output.trim()) return '';
return `\n<details>\n<summary>View lint errors</summary>\n\n\`\`\`\n${output.trim()}\n\`\`\`\n</details>`;
};
const anyFailure = [backend, mobile, web].includes('failure');
const title = anyFailure ? 'CI — Checks Failed' : 'CI — All Checks Passed';
const timestamp = new Date().toUTCString();
const body = `## ${title}
### Backend — ${status(backend)}
| Check | Result |
|---|---|
| Lint | ${status(backendLint)} |
| Test | ${status(backendTest)} |
| Typecheck | ${status(backendTypecheck)} |
${backendLint === 'failure' ? lintDetails(backendLintOutput) : ''}
### Mobile — ${status(mobile)}
| Check | Result |
|---|---|
| Lint | ${status(mobileLint)} |
| Test | ${status(mobileTest)} |
${mobileLint === 'failure' ? lintDetails(mobileLintOutput) : ''}
### Web — ${status(web)}
| Check | Result |
|---|---|
| Build | ${status(webBuild)} |
---
Last updated: \`${timestamp}\``;
const COMMENT_MARKER = '## CI —';
try {
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner,
repo,
issue_number: prNumber
}
);
const existing = comments.find(
c => c.body && c.body.startsWith(COMMENT_MARKER)
);
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body
});
}
} catch (err) {
console.error(err);
}
};