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

Commit 3e70a18

Browse files
authored
handle errors when posting comments (#274)
<!-- This is an auto-generated comment: release notes by openai --> ### Summary by OpenAI Release Notes: Bug fix: Added error handling and logging for updating or creating review comments in `commenter.ts`. This improves the reliability of the code by catching errors and providing warnings. > "Bugs can be pesky, > But we won't let them get too risky. > With error handling in place, > Our code is now a safer space." <!-- end of auto-generated comment: release notes by openai -->
1 parent 5d9174b commit 3e70a18

File tree

2 files changed

+93
-85
lines changed

2 files changed

+93
-85
lines changed

dist/index.js

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

src/commenter.ts

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -194,68 +194,70 @@ ${COMMENT_TAG}`
194194
info(
195195
`Submitting review for PR #${pullNumber}, total comments: ${this.reviewCommentsBuffer.length}`
196196
)
197-
try {
198-
let commentCounter = 0
199-
for (const comment of this.reviewCommentsBuffer) {
200-
info(`Posting comment: ${comment.message}`)
201-
let found = false
202-
const comments = await this.getCommentsAtRange(
203-
pullNumber,
204-
comment.path,
205-
comment.startLine,
206-
comment.endLine
207-
)
208-
for (const c of comments) {
209-
if (c.body.includes(COMMENT_TAG)) {
210-
info(
211-
`Updating review comment for ${comment.path}:${comment.startLine}-${comment.endLine}: ${comment.message}`
212-
)
197+
let commentCounter = 0
198+
for (const comment of this.reviewCommentsBuffer) {
199+
info(`Posting comment: ${comment.message}`)
200+
let found = false
201+
const comments = await this.getCommentsAtRange(
202+
pullNumber,
203+
comment.path,
204+
comment.startLine,
205+
comment.endLine
206+
)
207+
for (const c of comments) {
208+
if (c.body.includes(COMMENT_TAG)) {
209+
info(
210+
`Updating review comment for ${comment.path}:${comment.startLine}-${comment.endLine}: ${comment.message}`
211+
)
212+
try {
213213
await octokit.pulls.updateReviewComment({
214214
owner: repo.owner,
215215
repo: repo.repo,
216216
// eslint-disable-next-line camelcase
217217
comment_id: c.id,
218218
body: comment.message
219219
})
220-
found = true
221-
break
220+
} catch (e) {
221+
warning(`Failed to update review comment: ${e}`)
222222
}
223+
found = true
224+
break
223225
}
226+
}
224227

225-
if (!found) {
226-
info(
227-
`Creating new review comment for ${comment.path}:${comment.startLine}-${comment.endLine}: ${comment.message}`
228-
)
229-
const commentData: any = {
230-
owner: repo.owner,
231-
repo: repo.repo,
232-
// eslint-disable-next-line camelcase
233-
pull_number: pullNumber,
234-
// eslint-disable-next-line camelcase
235-
commit_id: commitId,
236-
body: comment.message,
237-
path: comment.path,
238-
line: comment.endLine
239-
}
240-
241-
if (comment.startLine !== comment.endLine) {
242-
// eslint-disable-next-line camelcase
243-
commentData.start_side = 'RIGHT'
244-
// eslint-disable-next-line camelcase
245-
commentData.start_line = comment.startLine
246-
}
228+
if (!found) {
229+
info(
230+
`Creating new review comment for ${comment.path}:${comment.startLine}-${comment.endLine}: ${comment.message}`
231+
)
232+
const commentData: any = {
233+
owner: repo.owner,
234+
repo: repo.repo,
235+
// eslint-disable-next-line camelcase
236+
pull_number: pullNumber,
237+
// eslint-disable-next-line camelcase
238+
commit_id: commitId,
239+
body: comment.message,
240+
path: comment.path,
241+
line: comment.endLine
242+
}
247243

244+
if (comment.startLine !== comment.endLine) {
245+
// eslint-disable-next-line camelcase
246+
commentData.start_side = 'RIGHT'
247+
// eslint-disable-next-line camelcase
248+
commentData.start_line = comment.startLine
249+
}
250+
try {
248251
await octokit.pulls.createReviewComment(commentData)
252+
} catch (e) {
253+
warning(`Failed to create review comment: ${e}`)
249254
}
250-
251-
commentCounter++
252-
info(
253-
`Comment ${commentCounter}/${this.reviewCommentsBuffer.length} posted`
254-
)
255255
}
256-
} catch (e) {
257-
warning(`Failed to submit review: ${e}`)
258-
throw e
256+
257+
commentCounter++
258+
info(
259+
`Comment ${commentCounter}/${this.reviewCommentsBuffer.length} posted`
260+
)
259261
}
260262
}
261263

0 commit comments

Comments
 (0)