|
1 | | -import { |
2 | | - IS_GITHUB_ACTION, |
3 | | - MAXIMUM_GITHUB_COMMENT_LENGTH, |
4 | | - GITHUB_ACTION_RUN_URL, |
5 | | -} from "./constants.ts"; |
6 | | -import { stringifyReport, type Report } from "./report.ts"; |
7 | | -import * as logger from "./logger.ts"; |
8 | | -import assert from "node:assert"; |
9 | | - |
10 | | -export async function reportOnGithubIssue(report: { |
11 | | - title: string; |
12 | | - reports: Report[]; |
13 | | -}) { |
14 | | - if (!IS_GITHUB_ACTION) { |
15 | | - return; |
16 | | - } |
17 | | - |
18 | | - await Promise.all( |
19 | | - [...getComments(report)].map((comment) => logger.report(comment)), |
20 | | - ); |
21 | | -} |
22 | | - |
23 | | -function* getComments({ |
24 | | - title, |
25 | | - reports, |
26 | | -}: { |
27 | | - title: string; |
28 | | - reports: Report[]; |
29 | | -}) { |
30 | | - let pending: Report[] = []; |
31 | | - |
32 | | - const canFit = (reports: Report[]) => |
33 | | - stringifyReport({ title, reports }).length < MAXIMUM_GITHUB_COMMENT_LENGTH; |
34 | | - |
35 | | - for (const report of reports) { |
36 | | - if (canFit([...pending, report])) { |
37 | | - pending.push(report); |
38 | | - continue; |
39 | | - } |
40 | | - |
41 | | - if (canFit([report])) { |
42 | | - yield stringifyReport({ title, reports: pending }); |
43 | | - pending = [report]; |
44 | | - continue; |
45 | | - } |
46 | | - |
47 | | - const shortReport = { |
48 | | - head: report.head, |
49 | | - body: `**Visit [this link](${GITHUB_ACTION_RUN_URL}) to download**`, |
50 | | - }; |
51 | | - |
52 | | - assert.ok(canFit([shortReport])); |
53 | | - |
54 | | - if (canFit([...pending, shortReport])) { |
55 | | - pending.push(shortReport); |
56 | | - continue; |
57 | | - } |
58 | | - |
59 | | - yield stringifyReport({ title, reports: pending }); |
60 | | - pending = [shortReport]; |
61 | | - } |
62 | | - |
63 | | - if (pending.length > 0) { |
64 | | - yield stringifyReport({ title, reports: pending }); |
65 | | - } |
66 | | -} |
| 1 | +import { |
| 2 | + IS_GITHUB_ACTION, |
| 3 | + MAXIMUM_GITHUB_COMMENT_LENGTH, |
| 4 | + GITHUB_ACTION_RUN_URL, |
| 5 | +} from "./constants.ts"; |
| 6 | +import { stringifyReport, type Report } from "./report.ts"; |
| 7 | +import * as logger from "./logger.ts"; |
| 8 | +import assert from "node:assert"; |
| 9 | + |
| 10 | +export async function reportOnGithubIssue(report: { |
| 11 | + title: string; |
| 12 | + reports: Report[]; |
| 13 | +}) { |
| 14 | + if (!IS_GITHUB_ACTION) { |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + await Promise.all( |
| 19 | + [...getComments(report)].map((comment) => logger.report(comment)), |
| 20 | + ); |
| 21 | +} |
| 22 | + |
| 23 | +function* getComments({ |
| 24 | + title, |
| 25 | + reports, |
| 26 | +}: { |
| 27 | + title: string; |
| 28 | + reports: Report[]; |
| 29 | +}) { |
| 30 | + let pending: Report[] = []; |
| 31 | + |
| 32 | + const canFit = (reports: Report[]) => |
| 33 | + stringifyReport({ title, reports }).length < MAXIMUM_GITHUB_COMMENT_LENGTH; |
| 34 | + |
| 35 | + for (const report of reports) { |
| 36 | + if (canFit([...pending, report])) { |
| 37 | + pending.push(report); |
| 38 | + continue; |
| 39 | + } |
| 40 | + |
| 41 | + if (canFit([report])) { |
| 42 | + yield stringifyReport({ title, reports: pending }); |
| 43 | + pending = [report]; |
| 44 | + continue; |
| 45 | + } |
| 46 | + |
| 47 | + const shortReport = { |
| 48 | + head: report.head, |
| 49 | + body: `**Visit [this link](${GITHUB_ACTION_RUN_URL}) to download**`, |
| 50 | + }; |
| 51 | + |
| 52 | + assert.ok(canFit([shortReport])); |
| 53 | + |
| 54 | + if (canFit([...pending, shortReport])) { |
| 55 | + pending.push(shortReport); |
| 56 | + continue; |
| 57 | + } |
| 58 | + |
| 59 | + yield stringifyReport({ title, reports: pending }); |
| 60 | + pending = [shortReport]; |
| 61 | + } |
| 62 | + |
| 63 | + if (pending.length > 0) { |
| 64 | + yield stringifyReport({ title, reports: pending }); |
| 65 | + } |
| 66 | +} |
0 commit comments