Skip to content

Commit a2c22a0

Browse files
committed
Fix
1 parent e255849 commit a2c22a0

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

src/logger.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ import { getOctokit } from "./octokit.ts";
44
import { codeBlock } from "./utilities.ts";
55
import { inspect } from "node:util";
66

7-
type Comment = Exclude<Awaited<ReturnType<typeof createComment>>, undefined>;
7+
type Comment = Awaited<ReturnType<typeof createComment>>;
88

99
async function createComment(body: string) {
10-
if (!IS_GITHUB_ACTION) {
11-
return;
12-
}
1310
const octokit = getOctokit();
1411

1512
return await octokit.rest.issues.createComment({
@@ -20,9 +17,6 @@ async function createComment(body: string) {
2017
}
2118

2219
async function updateComment(body: string, comment: Comment) {
23-
if (!IS_GITHUB_ACTION) {
24-
return;
25-
}
2620
const octokit = getOctokit();
2721

2822
return await octokit.rest.issues.updateComment({
@@ -34,39 +28,55 @@ async function updateComment(body: string, comment: Comment) {
3428

3529
let briefCommentRequest: ReturnType<typeof createComment> | undefined;
3630
export async function brief(body: string) {
37-
body += `\n__[details](${GITHUB_ACTION_JOB_URL})__`;
31+
console.log(body);
3832

39-
if (!briefCommentRequest) {
40-
briefCommentRequest = createComment(body);
41-
await briefCommentRequest;
33+
if (!IS_GITHUB_ACTION) {
4234
return;
4335
}
4436

45-
const comment = await briefCommentRequest;
37+
body += `\n__[details](${GITHUB_ACTION_JOB_URL})__`;
38+
39+
if (briefCommentRequest) {
40+
const comment = await briefCommentRequest;
41+
try {
42+
return await updateComment(body, comment);
43+
} catch {
44+
// No op
45+
}
46+
}
4647

47-
await updateComment(body, comment!);
48+
briefCommentRequest = createComment(body);
49+
return await briefCommentRequest;
4850
}
4951

50-
export async function error(error: Error): Promise<void> {
52+
export async function error(error: Error) {
53+
console.error(error);
54+
if (!IS_GITHUB_ACTION) {
55+
return;
56+
}
57+
5158
const text = `
5259
### [${error.name}]
5360
5461
${codeBlock(inspect(error))}
5562
`;
56-
console.error(error);
57-
await brief(text);
63+
return await brief(text);
5864
}
5965

6066
export async function report(body: string) {
6167
console.log(body);
6268

6369
if (briefCommentRequest) {
70+
const request = briefCommentRequest;
6471
briefCommentRequest = undefined;
6572

66-
const comment = await briefCommentRequest;
67-
await updateComment(body, comment!);
68-
return;
73+
try {
74+
const comment = await request;
75+
return await updateComment(body, comment);
76+
} catch {
77+
// No op
78+
}
6979
}
7080

71-
await createComment(body);
81+
return await createComment(body);
7282
}

src/report.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export const stringifyReport = ({
3838
}: {
3939
title: string;
4040
reports: Report[];
41-
}) => [title, ...reports.map(({ head, body }) => [head, body])].join("\n\n");
41+
}) =>
42+
[title, ...reports.flatMap(({ head, body }) => [head, body])].join("\n\n");
4243

4344
export function getReport({
4445
alternative,

src/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const commitChanges = async (directory: string, message: string) => {
5050
{ cwd: directory },
5151
);
5252

53-
const match = stdout.match(/^\[(?<commitHash>[a-f0-9]{40}) [a-f0-9]{7}]/);
53+
const match = stdout.match(/^\[(?<commitHash>[a-f0-9]{40}) [a-f0-9]{8}] /);
5454
if (!match?.groups!.commitHash) {
5555
throw new Error(`Unexpected commit hash '${stdout}'`);
5656
}

0 commit comments

Comments
 (0)