@@ -6,6 +6,7 @@ import {Bot} from './bot.js'
6
6
import { Commenter , COMMENT_REPLY_TAG , SUMMARIZE_TAG } from './commenter.js'
7
7
import { Inputs , Options , Prompts } from './options.js'
8
8
import * as tokenizer from './tokenizer.js'
9
+ import { ChatGPTError } from 'chatgpt'
9
10
10
11
const token = core . getInput ( 'token' )
11
12
? core . getInput ( 'token' )
@@ -18,7 +19,7 @@ export const codeReview = async (
18
19
bot : Bot ,
19
20
options : Options ,
20
21
prompts : Prompts
21
- ) => {
22
+ ) : Promise < void > => {
22
23
const commenter : Commenter = new Commenter ( )
23
24
24
25
const openai_concurrency_limit = pLimit ( options . openai_concurrency_limit )
@@ -122,12 +123,7 @@ export const codeReview = async (
122
123
patches . push ( [ line , patch ] )
123
124
}
124
125
if ( patches . length > 0 ) {
125
- return [ file . filename , file_content , file_diff , patches ] as [
126
- string ,
127
- string ,
128
- string ,
129
- [ number , string ] [ ]
130
- ]
126
+ return [ file . filename , file_content , file_diff , patches ]
131
127
} else {
132
128
return null
133
129
}
@@ -233,8 +229,9 @@ ${filename}: ${summary}
233
229
234
230
---
235
231
236
- ${ filter_ignored_files . length > 0
237
- ? `
232
+ ${
233
+ filter_ignored_files . length > 0
234
+ ? `
238
235
<details>
239
236
<summary>Files ignored due to filter (${ filter_ignored_files . length } )</summary>
240
237
@@ -244,23 +241,25 @@ ${filter_ignored_files.length > 0
244
241
245
242
</details>
246
243
`
247
- : ''
248
- }
244
+ : ''
245
+ }
249
246
250
- ${ skipped_files_to_summarize . length > 0
251
- ? `
247
+ ${
248
+ skipped_files_to_summarize . length > 0
249
+ ? `
252
250
<details>
253
- <summary>Files not summarized due to max files limit (${ skipped_files_to_summarize . length
254
- } )</summary>
251
+ <summary>Files not summarized due to max files limit (${
252
+ skipped_files_to_summarize . length
253
+ } )</summary>
255
254
256
255
### Not summarized
257
256
258
257
* ${ skipped_files_to_summarize . join ( '\n* ' ) }
259
258
260
259
</details>
261
260
`
262
- : ''
263
- }
261
+ : ''
262
+ }
264
263
`
265
264
266
265
next_summarize_ids = summarize_final_response_ids
@@ -388,10 +387,12 @@ ${skipped_files_to_summarize.length > 0
388
387
} else {
389
388
ins . comment_chain = 'no previous comments'
390
389
}
391
- } catch ( e : any ) {
392
- core . warning (
393
- `Failed to get comments: ${ e } , skipping. backtrace: ${ e . stack } `
394
- )
390
+ } catch ( e : unknown ) {
391
+ if ( e instanceof ChatGPTError ) {
392
+ core . warning (
393
+ `Failed to get comments: ${ e } , skipping. backtrace: ${ e . stack } `
394
+ )
395
+ }
395
396
}
396
397
397
398
try {
@@ -414,12 +415,14 @@ ${skipped_files_to_summarize.length > 0
414
415
line ,
415
416
`${ response } `
416
417
)
417
- } catch ( e : any ) {
418
- core . warning ( `Failed to comment: ${ e } , skipping.
418
+ } catch ( e : unknown ) {
419
+ if ( e instanceof ChatGPTError ) {
420
+ core . warning ( `Failed to comment: ${ e } , skipping.
419
421
backtrace: ${ e . stack }
420
422
filename: ${ filename }
421
423
line: ${ line }
422
424
patch: ${ patch } ` )
425
+ }
423
426
}
424
427
}
425
428
}
@@ -457,10 +460,12 @@ ${skipped_files_to_summarize.length > 0
457
460
if ( skipped_files_to_review . length > 0 ) {
458
461
// make bullet points for skipped files
459
462
const comment = `
460
- ${ skipped_files_to_review . length > 0
463
+ ${
464
+ skipped_files_to_review . length > 0
461
465
? `<details>
462
- <summary>Files not reviewed due to max files limit (${ skipped_files_to_review . length
463
- } )</summary>
466
+ <summary>Files not reviewed due to max files limit (${
467
+ skipped_files_to_review . length
468
+ } )</summary>
464
469
465
470
### Not reviewed
466
471
@@ -469,7 +474,7 @@ ${skipped_files_to_summarize.length > 0
469
474
</details>
470
475
`
471
476
: ''
472
- }
477
+ }
473
478
`
474
479
if ( comment . length > 0 ) {
475
480
await commenter . comment ( comment , SUMMARIZE_TAG , 'append' )
0 commit comments