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

Commit

Permalink
update index.js (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
harjotgill authored Jul 30, 2023
1 parent ef6b3ab commit 33d6f1c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 78 deletions.
72 changes: 37 additions & 35 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions src/commenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ ${COMMENT_TAG}`
}
}

async submitReview(pullNumber: number, commitId: string) {
async submitReview(pullNumber: number, commitId: string, statusMsg: string) {
if (this.reviewCommentsBuffer.length === 0) {
return
}
Expand Down Expand Up @@ -297,14 +297,20 @@ ${COMMENT_TAG}`
`Submitting review for PR #${pullNumber}, total comments: ${this.reviewCommentsBuffer.length}, review id: ${review.data.id}`
)

const body = `${COMMENT_GREETING}
${statusMsg}
`

await octokit.pulls.submitReview({
owner: repo.owner,
repo: repo.repo,
// eslint-disable-next-line camelcase
pull_number: pullNumber,
// eslint-disable-next-line camelcase
review_id: review.data.id,
event: 'COMMENT'
event: 'COMMENT',
body
})
} catch (e) {
warning(
Expand Down Expand Up @@ -732,11 +738,7 @@ ${chain}
}

// add in-progress status to the comment body
addInProgressStatus(
commentBody: string,
headCommitId: string,
highestReviewedCommitId: string
): string {
addInProgressStatus(commentBody: string, statusMsg: string): string {
const start = commentBody.indexOf(IN_PROGRESS_START_TAG)
const end = commentBody.indexOf(IN_PROGRESS_END_TAG)
// add to the beginning of the comment body if the marker doesn't exist
Expand All @@ -746,10 +748,7 @@ ${chain}
Currently reviewing new changes in this PR...
<details>
<summary>Details</summary>
The files that changed from the \`base\` of the PR and between \`${highestReviewedCommitId}\` and \`${headCommitId}\` commits are being reviewed.
</details>
${statusMsg}
${IN_PROGRESS_END_TAG}
Expand Down
67 changes: 35 additions & 32 deletions src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,37 @@ ${hunks.oldHunk}
return
}

let statusMsg = `<details>
<summary>Commits</summary>
Files that changed from the base of the PR and between ${highestReviewedCommitId} and ${
context.payload.pull_request.head.sha
} commits.
</details>
<details>
<summary>Files selected ${filesAndChanges.length}</summary>
${filesAndChanges
.map(([filename, , , patches]) => `* ${filename} (${patches.length} hunks)`)
.join('\n')}
</details>
${
filterIgnoredFiles.length > 0
? `
<details>
<summary>Files ignored due to filter (${filterIgnoredFiles.length})</summary>
* ${filterIgnoredFiles.map(file => file.filename).join('\n* ')}
</details>
`
: ''
}
`

// update the existing comment with in progress status
const inProgressSummarizeCmt = commenter.addInProgressStatus(
existingSummarizeCmtBody,
context.payload.pull_request.head.sha,
highestReviewedCommitId
statusMsg
)

// add in progress status to the summarize comment
Expand Down Expand Up @@ -402,7 +428,7 @@ ${filename}: ${summary}
if (releaseNotesResponse === '') {
info('release notes: nothing obtained from openai')
} else {
let message = '### Summary by CodeRabbit OSS\n\n'
let message = '### Summary by CodeRabbit\n\n'
message += releaseNotesResponse
try {
await commenter.updateDescription(
Expand Down Expand Up @@ -446,23 +472,10 @@ ${SHORT_SUMMARY_END_TAG}
### Ignoring further reviews
- Type \`@coderabbitai: ignore\` anywhere in the PR description to ignore further reviews from the bot.
</details>
${
filterIgnoredFiles.length > 0
? `
<details>
<summary>Files ignored due to filter (${filterIgnoredFiles.length})</summary>
### Ignored files
* ${filterIgnoredFiles.map(file => file.filename).join('\n* ')}
</details>
`
: ''
}

statusMsg += `
${
skippedFiles.length > 0
? `
Expand All @@ -471,15 +484,12 @@ ${
skippedFiles.length
})</summary>
### Not processed
* ${skippedFiles.join('\n* ')}
</details>
`
: ''
}
${
summariesFailed.length > 0
? `
Expand All @@ -488,15 +498,14 @@ ${
summariesFailed.length
})</summary>
### Failed to summarize
* ${summariesFailed.join('\n* ')}
</details>
`
: ''
}
`

if (!options.disableReview) {
const filesAndChangesReview = filesAndChanges.filter(([filename]) => {
const needsReview =
Expand Down Expand Up @@ -673,32 +682,25 @@ ${commentChain}

await Promise.all(reviewPromises)

summarizeComment += `
statusMsg += `
${
reviewsFailed.length > 0
? `<details>
<summary>Files not reviewed due to errors in the recent run (${
reviewsFailed.length
})</summary>
### Failed to review in the last run
<summary>Files not reviewed due to errors (${reviewsFailed.length})</summary>
* ${reviewsFailed.join('\n* ')}
</details>
`
: ''
}
${
reviewsSkipped.length > 0
? `<details>
<summary>Files not reviewed due to simple changes (${
reviewsSkipped.length
})</summary>
### Skipped review in the recent run
* ${reviewsSkipped.join('\n* ')}
</details>
Expand All @@ -719,7 +721,8 @@ ${
// post the review
await commenter.submitReview(
context.payload.pull_request.number,
commits[commits.length - 1].sha
commits[commits.length - 1].sha,
statusMsg
)
}

Expand Down

0 comments on commit 33d6f1c

Please sign in to comment.