@@ -13,7 +13,7 @@ const token = core.getInput('token')
13
13
const octokit = new Octokit ( { auth : `token ${ token } ` } )
14
14
const context = github . context
15
15
const repo = context . repo
16
- const limit = pLimit ( 2 )
16
+ const limit = pLimit ( 4 )
17
17
18
18
const MAX_TOKENS_FOR_EXTRA_CONTENT = 2500
19
19
@@ -170,15 +170,20 @@ export const codeReview = async (
170
170
const file_diff_tokens = tokenizer . get_token_count ( file_diff )
171
171
if ( file_diff_tokens < MAX_TOKENS_FOR_EXTRA_CONTENT ) {
172
172
// summarize diff
173
- const [ summarize_resp ] = await bot . chat (
174
- prompts . render_summarize_file_diff ( ins ) ,
175
- summarize_begin_ids
176
- )
177
- if ( ! summarize_resp ) {
178
- core . info ( 'summarize: nothing obtained from openai' )
173
+ try {
174
+ const [ summarize_resp ] = await bot . chat (
175
+ prompts . render_summarize_file_diff ( ins ) ,
176
+ summarize_begin_ids
177
+ )
178
+ if ( ! summarize_resp ) {
179
+ core . info ( 'summarize: nothing obtained from openai' )
180
+ return null
181
+ } else {
182
+ return [ filename , summarize_resp ]
183
+ }
184
+ } catch ( error ) {
185
+ core . warning ( `summarize: error from openai: ${ error } ` )
179
186
return null
180
- } else {
181
- return [ filename , summarize_resp ]
182
187
}
183
188
}
184
189
}
@@ -262,15 +267,19 @@ Tips:
262
267
if ( file_content . length > 0 ) {
263
268
const file_content_tokens = tokenizer . get_token_count ( file_content )
264
269
if ( file_content_tokens < MAX_TOKENS_FOR_EXTRA_CONTENT ) {
265
- // review file
266
- const [ resp , review_file_ids ] = await bot . chat (
267
- prompts . render_review_file ( ins ) ,
268
- next_review_ids
269
- )
270
- if ( ! resp ) {
271
- core . info ( 'review: nothing obtained from openai' )
272
- } else {
273
- next_review_ids = review_file_ids
270
+ try {
271
+ // review file
272
+ const [ resp , review_file_ids ] = await bot . chat (
273
+ prompts . render_review_file ( ins ) ,
274
+ next_review_ids
275
+ )
276
+ if ( ! resp ) {
277
+ core . info ( 'review: nothing obtained from openai' )
278
+ } else {
279
+ next_review_ids = review_file_ids
280
+ }
281
+ } catch ( error ) {
282
+ core . warning ( `review: error from openai: ${ error } ` )
274
283
}
275
284
} else {
276
285
core . info (
@@ -282,15 +291,19 @@ Tips:
282
291
if ( file_diff . length > 0 ) {
283
292
const file_diff_tokens = tokenizer . get_token_count ( file_diff )
284
293
if ( file_diff_tokens < MAX_TOKENS_FOR_EXTRA_CONTENT ) {
285
- // review diff
286
- const [ resp , review_diff_ids ] = await bot . chat (
287
- prompts . render_review_file_diff ( ins ) ,
288
- next_review_ids
289
- )
290
- if ( ! resp ) {
291
- core . info ( 'review: nothing obtained from openai' )
292
- } else {
293
- next_review_ids = review_diff_ids
294
+ try {
295
+ // review diff
296
+ const [ resp , review_diff_ids ] = await bot . chat (
297
+ prompts . render_review_file_diff ( ins ) ,
298
+ next_review_ids
299
+ )
300
+ if ( ! resp ) {
301
+ core . info ( 'review: nothing obtained from openai' )
302
+ } else {
303
+ next_review_ids = review_diff_ids
304
+ }
305
+ } catch ( error ) {
306
+ core . warning ( `review: error from openai: ${ error } ` )
294
307
}
295
308
} else {
296
309
core . info (
@@ -313,33 +326,41 @@ Tips:
313
326
core . warning ( 'No pull request found, skipping.' )
314
327
continue
315
328
}
316
- // get existing comments on the line
317
- const all_chains = await commenter . get_conversation_chains_at_line (
318
- context . payload . pull_request . number ,
319
- filename ,
320
- line ,
321
- COMMENT_REPLY_TAG
322
- )
323
329
324
- if ( all_chains . length > 0 ) {
325
- ins . comment_chain = all_chains
326
- } else {
327
- ins . comment_chain = 'no previous comments'
330
+ try {
331
+ // get existing comments on the line
332
+ const all_chains =
333
+ await commenter . get_conversation_chains_at_line (
334
+ context . payload . pull_request . number ,
335
+ filename ,
336
+ line ,
337
+ COMMENT_REPLY_TAG
338
+ )
339
+
340
+ if ( all_chains . length > 0 ) {
341
+ ins . comment_chain = all_chains
342
+ } else {
343
+ ins . comment_chain = 'no previous comments'
344
+ }
345
+ } catch ( e : any ) {
346
+ core . warning (
347
+ `Failed to get comments: ${ e } , skipping. backtrace: ${ e . stack } `
348
+ )
328
349
}
329
350
330
- const [ response , patch_ids ] = await bot . chat (
331
- prompts . render_review_patch ( ins ) ,
332
- next_review_ids
333
- )
334
- if ( ! response ) {
335
- core . info ( 'review: nothing obtained from openai' )
336
- continue
337
- }
338
- next_review_ids = patch_ids
339
- if ( ! options . review_comment_lgtm && response . includes ( 'LGTM' ) ) {
340
- continue
341
- }
342
351
try {
352
+ const [ response , patch_ids ] = await bot . chat (
353
+ prompts . render_review_patch ( ins ) ,
354
+ next_review_ids
355
+ )
356
+ if ( ! response ) {
357
+ core . info ( 'review: nothing obtained from openai' )
358
+ continue
359
+ }
360
+ next_review_ids = patch_ids
361
+ if ( ! options . review_comment_lgtm && response . includes ( 'LGTM' ) ) {
362
+ continue
363
+ }
343
364
await commenter . review_comment (
344
365
context . payload . pull_request . number ,
345
366
commits [ commits . length - 1 ] . sha ,
0 commit comments