Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit a024c41

Browse files
authored
error handling (#56)
<!-- This is an auto-generated comment: release notes by openai --> ### Summary by OpenAI **Release Notes** This pull request includes improvements to error handling in the `review.ts` file. The changes made aim to improve the reliability and robustness of the code by handling potential errors more gracefully. This is a "Bug fix" that increases the `limit` variable and adds try-catch blocks around various sections of code to handle errors from OpenAI and the GitHub API. <!-- end of auto-generated comment: release notes by openai -->
1 parent d444110 commit a024c41

File tree

2 files changed

+126
-84
lines changed

2 files changed

+126
-84
lines changed

dist/index.js

Lines changed: 55 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/review.ts

Lines changed: 71 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const token = core.getInput('token')
1313
const octokit = new Octokit({auth: `token ${token}`})
1414
const context = github.context
1515
const repo = context.repo
16-
const limit = pLimit(2)
16+
const limit = pLimit(4)
1717

1818
const MAX_TOKENS_FOR_EXTRA_CONTENT = 2500
1919

@@ -170,15 +170,20 @@ export const codeReview = async (
170170
const file_diff_tokens = tokenizer.get_token_count(file_diff)
171171
if (file_diff_tokens < MAX_TOKENS_FOR_EXTRA_CONTENT) {
172172
// 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}`)
179186
return null
180-
} else {
181-
return [filename, summarize_resp]
182187
}
183188
}
184189
}
@@ -262,15 +267,19 @@ Tips:
262267
if (file_content.length > 0) {
263268
const file_content_tokens = tokenizer.get_token_count(file_content)
264269
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}`)
274283
}
275284
} else {
276285
core.info(
@@ -282,15 +291,19 @@ Tips:
282291
if (file_diff.length > 0) {
283292
const file_diff_tokens = tokenizer.get_token_count(file_diff)
284293
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}`)
294307
}
295308
} else {
296309
core.info(
@@ -313,33 +326,41 @@ Tips:
313326
core.warning('No pull request found, skipping.')
314327
continue
315328
}
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-
)
323329

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+
)
328349
}
329350

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-
}
342351
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+
}
343364
await commenter.review_comment(
344365
context.payload.pull_request.number,
345366
commits[commits.length - 1].sha,

0 commit comments

Comments
 (0)