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

Commit 25790f9

Browse files
authored
submit empty review when there are no comments (#393)
1 parent a133f76 commit 25790f9

File tree

3 files changed

+120
-78
lines changed

3 files changed

+120
-78
lines changed

dist/index.js

+54-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commenter.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,28 @@ ${COMMENT_TAG}`
232232
}
233233

234234
async submitReview(pullNumber: number, commitId: string, statusMsg: string) {
235+
const body = `${COMMENT_GREETING}
236+
237+
${statusMsg}
238+
`
239+
235240
if (this.reviewCommentsBuffer.length === 0) {
241+
// Submit empty review with statusMsg
242+
info(`Submitting empty review for PR #${pullNumber}`)
243+
try {
244+
await octokit.pulls.createReview({
245+
owner: repo.owner,
246+
repo: repo.repo,
247+
// eslint-disable-next-line camelcase
248+
pull_number: pullNumber,
249+
// eslint-disable-next-line camelcase
250+
commit_id: commitId,
251+
event: 'COMMENT',
252+
body
253+
})
254+
} catch (e) {
255+
warning(`Failed to submit empty review: ${e}`)
256+
}
236257
return
237258
}
238259
for (const comment of this.reviewCommentsBuffer) {
@@ -297,11 +318,6 @@ ${COMMENT_TAG}`
297318
`Submitting review for PR #${pullNumber}, total comments: ${this.reviewCommentsBuffer.length}, review id: ${review.data.id}`
298319
)
299320

300-
const body = `${COMMENT_GREETING}
301-
302-
${statusMsg}
303-
`
304-
305321
await octokit.pulls.submitReview({
306322
owner: repo.owner,
307323
repo: repo.repo,

src/review.ts

+45-41
Original file line numberDiff line numberDiff line change
@@ -619,51 +619,55 @@ ${commentChain}
619619
`
620620
}
621621

622-
// perform review
623-
try {
624-
const [response] = await heavyBot.chat(
625-
prompts.renderReviewFileDiff(ins),
626-
{}
627-
)
628-
if (response === '') {
629-
info('review: nothing obtained from openai')
630-
reviewsFailed.push(`${filename} (no response)`)
631-
return
632-
}
633-
// parse review
634-
const reviews = parseReview(response, patches, options.debug)
635-
for (const review of reviews) {
636-
// check for LGTM
637-
if (
638-
!options.reviewCommentLGTM &&
639-
(review.comment.includes('LGTM') ||
640-
review.comment.includes('looks good to me'))
641-
) {
642-
continue
643-
}
644-
if (context.payload.pull_request == null) {
645-
warning('No pull request found, skipping.')
646-
continue
622+
if (patchesPacked > 0) {
623+
// perform review
624+
try {
625+
const [response] = await heavyBot.chat(
626+
prompts.renderReviewFileDiff(ins),
627+
{}
628+
)
629+
if (response === '') {
630+
info('review: nothing obtained from openai')
631+
reviewsFailed.push(`${filename} (no response)`)
632+
return
647633
}
634+
// parse review
635+
const reviews = parseReview(response, patches, options.debug)
636+
for (const review of reviews) {
637+
// check for LGTM
638+
if (
639+
!options.reviewCommentLGTM &&
640+
(review.comment.includes('LGTM') ||
641+
review.comment.includes('looks good to me'))
642+
) {
643+
continue
644+
}
645+
if (context.payload.pull_request == null) {
646+
warning('No pull request found, skipping.')
647+
continue
648+
}
648649

649-
try {
650-
await commenter.bufferReviewComment(
651-
filename,
652-
review.startLine,
653-
review.endLine,
654-
`${review.comment}`
655-
)
656-
} catch (e: any) {
657-
reviewsFailed.push(`${filename} comment failed (${e as string})`)
650+
try {
651+
await commenter.bufferReviewComment(
652+
filename,
653+
review.startLine,
654+
review.endLine,
655+
`${review.comment}`
656+
)
657+
} catch (e: any) {
658+
reviewsFailed.push(`${filename} comment failed (${e as string})`)
659+
}
658660
}
661+
} catch (e: any) {
662+
warning(
663+
`Failed to review: ${e as string}, skipping. backtrace: ${
664+
e.stack as string
665+
}`
666+
)
667+
reviewsFailed.push(`${filename} (${e as string})`)
659668
}
660-
} catch (e: any) {
661-
warning(
662-
`Failed to review: ${e as string}, skipping. backtrace: ${
663-
e.stack as string
664-
}`
665-
)
666-
reviewsFailed.push(`${filename} (${e as string})`)
669+
} else {
670+
reviewsSkipped.push(`${filename} (diff too large)`)
667671
}
668672
}
669673

0 commit comments

Comments
 (0)