@@ -3,13 +3,15 @@ import {
3
3
error ,
4
4
getBooleanInput ,
5
5
getInput ,
6
+ info ,
6
7
setFailed ,
7
8
summary ,
8
9
} from "@actions/core" ;
9
10
import { getOctokit } from "@actions/github" ;
10
11
import { context } from "@actions/github/lib/utils" ;
11
12
import { existsSync , readFile } from "fs" ;
12
13
import { promisify } from "util" ;
14
+ import { RequestError } from "@octokit/request-error" ;
13
15
14
16
import { chart } from "./chart" ;
15
17
import { fromString } from "./clover" ;
@@ -186,6 +188,21 @@ function* checkThreshold(c: Stats, o?: Stats) {
186
188
}
187
189
}
188
190
191
+ const scopesToString = ( scopes : null | string ) =>
192
+ scopes ?. split ( / , \s + / ) ?. join ( ", " ) || "(empty)" ;
193
+
194
+ const errorToString = ( e : any ) =>
195
+ e +
196
+ ( e instanceof Error
197
+ ? ( e instanceof RequestError
198
+ ? `\nRequest: ${ e . request . method } ${ e . request . url } ` +
199
+ `\nResponse Scopes: ${ scopesToString (
200
+ e . response ?. headers ?. [ "x-oauth-scopes" ]
201
+ ) } ` +
202
+ `\nResponse Headers: ${ JSON . stringify ( e . response ?. headers || [ ] ) } `
203
+ : "" ) + `\nStack: ${ e . stack } `
204
+ : "" ) ;
205
+
189
206
const notFoundMessage =
190
207
"was not found, please check if the path is valid, or if it exists." ;
191
208
@@ -273,8 +290,15 @@ ${signature}`;
273
290
const u = await github . rest . users . getAuthenticated ( ) ;
274
291
filter = ( c : any ) => c ?. user ?. login === u . data . login ;
275
292
276
- debug ( "Using a PAT from " + u . data . login ) ;
277
- } catch ( e ) { }
293
+ info (
294
+ "Using a PAT from " +
295
+ u . data . login +
296
+ " with scopes: " +
297
+ scopesToString ( u . headers ?. [ "x-oauth-scopes" ] )
298
+ ) ;
299
+ } catch ( e ) {
300
+ debug ( errorToString ( e ) ) ;
301
+ }
278
302
279
303
let commentId = null ;
280
304
try {
@@ -291,7 +315,7 @@ ${signature}`;
291
315
commentId = c . id ;
292
316
}
293
317
} catch ( e ) {
294
- error ( e ) ;
318
+ error ( errorToString ( e ) ) ;
295
319
}
296
320
297
321
if ( commentId ) {
@@ -305,11 +329,19 @@ ${signature}`;
305
329
} catch { }
306
330
}
307
331
308
- await github . rest . issues . createComment ( {
309
- ...context . repo ,
310
- issue_number : context . issue . number ,
311
- body,
312
- } ) ;
332
+ await github . rest . issues
333
+ . createComment ( {
334
+ ...context . repo ,
335
+ issue_number : context . issue . number ,
336
+ body,
337
+ } )
338
+ . catch ( ( e : Error ) => {
339
+ throw new Error (
340
+ "Failed to create a new comment with: " +
341
+ e . message +
342
+ ( e . stack ? ". Stack: " + e . stack : "" )
343
+ ) ;
344
+ } ) ;
313
345
} ;
314
346
315
- run ( ) . catch ( ( err : Error ) => setFailed ( err + " Stack: " + err . stack ) ) ;
347
+ run ( ) . catch ( ( err : Error ) => setFailed ( errorToString ( err ) ) ) ;
0 commit comments