@@ -4,12 +4,9 @@ import { getOctokit } from "./octokit.ts";
44import { codeBlock } from "./utilities.ts" ;
55import { inspect } from "node:util" ;
66
7- type Comment = Exclude < Awaited < ReturnType < typeof createComment > > , undefined > ;
7+ type Comment = Awaited < ReturnType < typeof createComment > > ;
88
99async 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
2219async 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
3529let briefCommentRequest : ReturnType < typeof createComment > | undefined ;
3630export 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
6066export 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}
0 commit comments