repo_name stringlengths 1 62 | dataset stringclasses 1 value | lang stringclasses 11 values | pr_id int64 1 20.1k | owner stringlengths 2 34 | reviewer stringlengths 2 39 | diff_hunk stringlengths 15 262k | code_review_comment stringlengths 1 99.6k |
|---|---|---|---|---|---|---|---|
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -10,7 +11,10 @@ import * as tokenizer from './tokenizer.js'
const token = core.getInput('token')
? core.getInput('token')
: process.env.GITHUB_TOKEN | :robot: OpenAI
The code change looks good. However, it would be better to use the `||` operator instead of ternary operator for better readability.
```suggestion
const token = core.getInput('token') || process.env.GITHUB_TOKEN;
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -10,7 +11,10 @@ import * as tokenizer from './tokenizer.js'
const token = core.getInput('token')
? core.getInput('token')
: process.env.GITHUB_TOKEN
-const octokit = new Octokit({auth: `token ${token}`})
+
+const RetryOctokit = Octokit.plugin(retry)
+const octokit = new RetryOctokit({auth: `token ${token}`}) | :robot: OpenAI
The `RetryOctokit` class is created by adding the `retry` plugin to the `Octokit` class. This is a good approach to add retry functionality to the `Octokit` instance. However, it would be better to move this code to a separate function or module so that it can be reused in other parts of the codebase.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -127,11 +131,10 @@ export const codeReview = async (
continue
}
const hunks_str = `
-\`\`\`new_hunk
+\`\`\`new_hunk_for_review
${hunks.new_hunk}
\`\`\`
-
-\`\`\`old_hunk
+\`\`\`old_hunk_for_context
${hunks.old_hunk}
\`\`\`
` | :robot: OpenAI
The `hunks_str` variable is created by concatenating multiple strings. This can be error-prone and hard to read. It would be better to use template literals instead of string concatenation.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -272,6 +275,10 @@ ${filename}: ${summary}
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging \`@openai\` in a reply.
+### Code suggestions
+- The bot will sometimes make code suggestion. Sometimes the line number ranges may be misaligned. Please make sure to review the suggestion carefully before committing.
+- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
+ | :robot: OpenAI
The changes look good. However, it would be better to use bullet points for better readability.
```suggestion
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -2,12 +2,13 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {Octokit} from '@octokit/action'
-import {ChatGPTError} from 'chatgpt'
+import {retry} from '@octokit/plugin-retry' | :robot: OpenAI
The addition of the `@octokit/plugin-retry` plugin is a good improvement to handle failed requests. However, it's important to note that this plugin may introduce data consistency issues if not handled properly. Please ensure that the retry plugin is used only for idempotent operations or that you have implemented a mechanism to handle data consistency issues.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -534,10 +532,8 @@ ${chain}
this.issueCommentsCache[target] = all_comments
return all_comments
- } catch (e: unknown) {
- if (e instanceof ChatGPTError) {
- core.warning(`Failed to list comments: ${e}`)
- }
+ } catch (e: any) {
+ core.warning(`Failed to list comments: ${e}`)
return all_comments
}
} | :robot: OpenAI
Good job on improving error handling. However, please consider catching specific errors instead of using `any`. This will help with debugging and make the code more maintainable.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -15,7 +16,9 @@ const token = core.getInput('token')
? core.getInput('token')
: process.env.GITHUB_TOKEN
-const octokit = new Octokit({auth: `token ${token}`})
+const RetryOctokit = Octokit.plugin(retry)
+const octokit = new RetryOctokit({auth: `token ${token}`}) | :robot: OpenAI
The addition of the retry plugin is a good improvement to handle failed requests. However, it would be better to use a new `RetryOctokit` instance instead of modifying the existing `octokit` instance. This will ensure that the retry plugin is only used when necessary and does not affect other parts of the code that do not require retries.
```suggestion
const RetryOctokit = Octokit.plugin(retry)
const retryOctokit = new RetryOctokit({auth: `token ${token}`})
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 146 | coderabbitai | github-actions[bot] | @@ -29,6 +29,7 @@
"@actions/github": "^5.1.1",
"@dqbd/tiktoken": "^1.0.2",
"@octokit/action": "^5.0.2",
+ "@octokit/plugin-retry": "^4.1.3", | :robot: OpenAI
The addition of `@octokit/plugin-retry` as a dependency may introduce data consistency issues if not handled properly. Please ensure that the retry plugin is used in a way that does not compromise data consistency.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 146 | coderabbitai | github-actions[bot] | @@ -29,6 +29,7 @@
"@actions/github": "^5.1.1",
"@dqbd/tiktoken": "^1.0.2",
"@octokit/action": "^5.0.2", | :robot: OpenAI
Please update the description for the existing input to reflect the new changes.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -1,6 +1,7 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {Octokit} from '@octokit/action' | :robot: OpenAI
The changes look good. However, it would be better to add a comment explaining why the `Octokit` instance is being replaced with a `RetryOctokit` instance. This will help future developers understand the code better.
```suggestion
// Replace Octokit instance with RetryOctokit instance to enable retrying failed requests.
const RetryOctokit = Octokit.plugin(retry)
const octokit = new RetryOctokit({auth: `token ${token}`})
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -272,6 +275,10 @@ ${filename}: ${summary}
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging \`@openai\` in a reply.
+### Code suggestions
+- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
+- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
+
--- | :robot: OpenAI
The text in this section is not very clear. It would be better to provide more detailed instructions on how to use the bot's code suggestions feature.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -400,7 +407,7 @@ ${
let comment_chain = ''
try {
- const all_chains = await commenter.get_conversation_chains_within_range(
+ const all_chains = await commenter.get_comment_chains_within_range(
context.payload.pull_request.number,
filename,
start_line, | :robot: OpenAI
The `get_comment_chains_within_range` function is called with four arguments. The last three arguments are related to the range of lines where the comment chains should be retrieved. It would be better to group these arguments into an object or a tuple to make the function call more readable.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 146 | coderabbitai | github-actions[bot] | @@ -434,7 +441,7 @@ ${patch}
`
if (comment_chain !== '') {
ins.patches += `
-\`\`\`comment_chain
+\`\`\`comment_chains_for_review
${comment_chain}
\`\`\`
` | :robot: OpenAI
The `patches` variable is updated by concatenating multiple strings. This can be error-prone and hard to read. It would be better to use template literals instead of string concatenation.
That's all for my review. Let me know if you have any questions or concerns.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 144 | coderabbitai | github-actions[bot] | @@ -0,0 +1,13 @@
+name: Tag latest
+
+on:
+ release:
+ types: [published, edited]
+
+jobs:
+ actions-tagger:
+ runs-on: windows-latest
+ steps:
+ - uses: Actions-R-Us/actions-tagger@latest
+ with:
+ publish_latest_tag: true | :robot: OpenAI
This workflow file adds a new job that runs on release events and tags the latest commit using an external action. However, there is no error handling in case the external action fails. It's important to add proper error handling to ensure that the workflow doesn't fail silently. Additionally, it's recommended to specify the version of the external action being used instead of always using the latest version. Finally, it's good practice to use a more descriptive name for the job instead of `actions-tagger`.
```suggestion
name: Tag latest
on:
release:
types: [published, edited]
jobs:
tag-latest-commit:
runs-on: windows-latest
steps:
- name: Tag latest commit
uses: Actions-R-Us/actions-tagger@v1.0.0
with:
publish_latest_tag: true
- name: Check if tag was created
run: |
if [ -z "$(git tag --points-at HEAD)" ]; then
echo "Tag was not created"
exit 1
fi
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 141 | coderabbitai | github-actions[bot] | @@ -200,7 +200,7 @@ inputs:
Don't echo back the code provided to you as the
line number range is sufficient to map your comment to the relevant code
section in GitHub. Markdown format is preferred for text. Fenced code
- blocks should be used for complete code suggestions that replace code
+ blocks should be used for new code or code suggestions that replace code
at those exact line number ranges. It's important that the code
suggestions are complete, correctly formatted and without line number
annotations so that they can be committed as-is. | :robot: OpenAI
The sentence "It's important that the code suggestions are complete, correctly formatted and without line number annotations so that they can be committed as-is." is a bit confusing. Can you rephrase it to make it clearer?
<!-- This is an auto-generated reply by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 141 | coderabbitai | github-actions[bot] | @@ -214,6 +214,11 @@ inputs:
<start_line_number>-<end_line_number>:
<review markdown>
---
+ <start_line_number>-<end_line_number>:
+ <review markdown>
+ ```<language>
+ <new code suggestion>
+ ```
...
| :robot: OpenAI
It would be helpful to provide some examples of how to use the new guidelines in practice. Could you please add some examples to the documentation?
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 141 | coderabbitai | github-actions[bot] | @@ -200,10 +200,10 @@ inputs:
Don't echo back the code provided to you as the
line number range is sufficient to map your comment to the relevant code
section in GitHub. Markdown format is preferred for text. Fenced code
- blocks should be used for complete code suggestions that replace code
- at those exact line number ranges. It's important that the code
- suggestions are complete, correctly formatted and without line number
- annotations so that they can be committed as-is.
+ blocks should be used for new code and replacement code suggestions.
+ Replacement code suggestions must be complete, correctly formatted and
+ most importantly, map exactly to the line number ranges that need to
+ be replaced. | :robot: OpenAI
I suggest rephrasing this section to make it clearer that fenced code blocks should be used only for new or replacement code suggestions, not for all code comments. Also, it would be helpful to provide an example of a correctly formatted fenced code block.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 140 | coderabbitai | github-actions[bot] | @@ -457,8 +456,8 @@ ${comment_chain}
return
}
// parse review
- const reviewMap = parseOpenAIReview(response, options.debug)
- for (const [, review] of reviewMap) {
+ const reviews = parseReview(response, options.debug)
+ for (const review of reviews) {
// check for LGTM
if (
!options.review_comment_lgtm && | :robot: OpenAI
The `parseReview` function seems to be parsing OpenAI reviews, but the function name doesn't reflect that. It might be better to rename it to `parseOpenAIReview` or something similar.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 140 | coderabbitai | github-actions[bot] | @@ -671,9 +668,9 @@ function parseOpenAIReview(
const lineNumberRangeMatch = line.match(lineNumberRangeRegex)
if (lineNumberRangeMatch) {
- // If there is a previous comment, store it in the reviews Map
+ // If there is a previous comment, store it in the reviews
if (currentStartLine !== null && currentEndLine !== null) {
- reviews.set(`${currentStartLine}-${currentEndLine}`, {
+ reviews.push({
start_line: currentStartLine,
end_line: currentEndLine,
comment: currentComment.trim() | :robot: OpenAI
In the `parseReview` function, the `reviews` array is being used to store objects with `start_line`, `end_line`, and `comment` properties. However, this information can be better represented using a map where the key is a string in the format `<start_line>-<end_line>` and the value is the object with `start_line`, `end_line`, and `comment` properties. This will make it easier to look up comments for a specific line range later on.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 140 | coderabbitai | github-actions[bot] | @@ -156,7 +156,7 @@ ${tag}`
for (const comment of comments) {
if (comment.body.includes(tag)) {
core.info(
- `Updating review comment for ${path}:${end_line}: ${message}`
+ `Updating review comment for ${path}:${start_line}-${end_line}: ${message}`
)
await octokit.pulls.updateReviewComment({
owner: repo.owner, | :robot: OpenAI
The `core.info` message in line 158 should be updated to include the `start_line` and `end_line` variables instead of just `end_line`. This will make it easier to identify which comment is being updated.
```suggestion
core.info(
`Updating review comment for ${path}:${start_line}-${end_line}: ${message}`
)
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 140 | coderabbitai | github-actions[bot] | @@ -279,14 +279,32 @@ ${COMMENT_REPLY_TAG}
)
}
- async get_conversation_chains_at_range(
+ async get_comments_at_range(
+ pull_number: number,
+ path: string,
+ start_line: number,
+ end_line: number
+ ) {
+ const comments = await this.list_review_comments(pull_number)
+ return comments.filter(
+ (comment: any) =>
+ comment.path === path &&
+ comment.body !== '' &&
+ ((comment.start_line !== undefined &&
+ comment.start_line === start_line &&
+ comment.line === end_line) ||
+ comment.line === end_line)
+ )
+ }
+ | :robot: OpenAI
The function `get_comments_at_range` in line 282 should be renamed to `get_comments_within_range` to match the new function name in line 264. Additionally, the new function `get_conversation_chains_within_range` in lines 300-306 should be added to retrieve all conversation chains within a given range.
```suggestion
async get_comments_within_range(
pull_number: number,
path: string,
start_line: number,
end_line: number
) {
const comments = await this.list_review_comments(pull_number)
return comments.filter(
(comment: any) =>
comment.path === path &&
comment.body !== '' &&
((comment.start_line !== undefined &&
comment.start_line === start_line &&
comment.line === end_line) ||
comment.line === end_line)
)
}
async get_conversation_chains_within_range(
pull_number: number,
path: string,
start_line: number,
end_line: number,
tag = ''
) {
const existing_comments = await this.get_comments_within_range(
pull_number,
path,
start_line,
end_line
)
// implementation here
}
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 140 | coderabbitai | github-actions[bot] | @@ -279,14 +279,32 @@ ${COMMENT_REPLY_TAG}
)
}
- async get_conversation_chains_at_range(
+ async get_comments_at_range(
+ pull_number: number,
+ path: string,
+ start_line: number,
+ end_line: number
+ ) {
+ const comments = await this.list_review_comments(pull_number)
+ return comments.filter(
+ (comment: any) =>
+ comment.path === path &&
+ comment.body !== '' &&
+ ((comment.start_line !== undefined &&
+ comment.start_line === start_line &&
+ comment.line === end_line) ||
+ comment.line === end_line)
+ )
+ }
+
+ async get_conversation_chains_within_range(
pull_number: number,
path: string,
start_line: number,
end_line: number,
tag = ''
) { | :robot: OpenAI
The function name `get_conversation_chains_at_range` has been changed to `get_conversation_chains_within_range`. However, the function signature still uses the old name. It should be updated to reflect the new name.
```suggestion
300: async get_conversation_chains_within_range(
301: pull_number: number,
302: path: string,
303: start_line: number,
304: end_line: number,
305: tag = ''
306: ) {
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 140 | coderabbitai | github-actions[bot] | @@ -202,8 +202,8 @@ inputs:
section in GitHub. Markdown format is preferred for text. Fenced code
blocks should be used for complete code suggestions that replace code
at those exact line number ranges. It's important that the code
- suggestions are complete and correctly formatted so that they can be
- committed as-is.
+ suggestions are complete, correctly formatted and without line number
+ annotations so that they can be committed as-is. | :robot: OpenAI
It's important to note that the suggestion in this hunk is incomplete. It mentions that fenced code blocks should be used for complete code suggestions, but it doesn't actually provide an example of what a complete code suggestion would look like. It might be helpful to add an example here to clarify.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 140 | coderabbitai | github-actions[bot] | @@ -202,8 +202,8 @@ inputs:
section in GitHub. Markdown format is preferred for text. Fenced code
blocks should be used for complete code suggestions that replace code
at those exact line number ranges. It's important that the code
- suggestions are complete and correctly formatted so that they can be
- committed as-is.
+ suggestions are complete, correctly formatted and without line number
+ annotations so that they can be committed as-is.
<start_line_number>-<end_line_number>:
<review markdown> | :robot: OpenAI
```suggestion
207: section in GitHub. Markdown format is preferred for text. Fenced code
208: blocks should be used for complete code suggestions that replace code
209: at those exact line number ranges. It's important that the code
```
This suggestion adds an example of a complete code suggestion to the previous hunk.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 140 | coderabbitai | github-actions[bot] | @@ -261,7 +261,7 @@ ${COMMENT_REPLY_TAG}
}
}
- async get_comments_at_range(
+ async get_comments_within_range(
pull_number: number,
path: string,
start_line: number, | :robot: OpenAI
The function name `get_comments_at_range` in line 264 should be changed to `get_comments_within_range` to better reflect its functionality.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 138 | coderabbitai | github-actions[bot] | @@ -1,7 +1,6 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {Octokit} from '@octokit/action'
-import {ChatGPTError} from 'chatgpt'
import pLimit from 'p-limit'
import {Bot} from './bot.js' | :robot: OpenAI
It would be helpful to provide a description of the changes made in the pull request description.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 138 | coderabbitai | github-actions[bot] | @@ -415,12 +414,10 @@ ${
} else {
comment_chain = ''
}
- } catch (e: unknown) {
- if (e instanceof ChatGPTError) {
- core.warning(
- `Failed to get comments: ${e}, skipping. backtrace: ${e.stack}`
- )
- }
+ } catch (e: any) {
+ core.warning(
+ `Failed to get comments: ${e}, skipping. backtrace: ${e.stack}`
+ )
}
// try packing comment_chain into this request
const comment_chain_tokens = tokenizer.get_token_count(comment_chain) | :robot: OpenAI
In the try-catch block, it is catching all exceptions with `any`. It would be better to catch specific exceptions instead of using `any`.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -143,7 +143,6 @@ export class TokenLimits {
max_tokens: number
request_tokens: number
response_tokens: number
- extra_content_tokens: number
constructor(model = 'gpt-3.5-turbo') {
if (model === 'gpt-4-32k') { | :robot: OpenAI
The `model` parameter in the constructor is not used. Is it necessary to have it as a parameter? If not, it can be removed to simplify the code.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -134,11 +134,20 @@ export const handleReviewComment = async (
inputs.summary = summary.body
}
+ // get tokens so far
+ let tokens = tokenizer.get_token_count(prompts.render_comment(inputs))
+
+ // pack file content and diff into the inputs if they are not too long
if (file_content.length > 0) {
+ // count occurrences of $file_content in prompt
+ const file_content_count =
+ prompts.summarize_file_diff.split('$file_content').length - 1
const file_content_tokens = tokenizer.get_token_count(file_content)
if (
- file_content_tokens < options.heavy_token_limits.extra_content_tokens
+ tokens + file_content_tokens * file_content_count <=
+ options.heavy_token_limits.request_tokens
) {
+ tokens += file_content_tokens * file_content_count
inputs.file_content = file_content
}
} | :robot: OpenAI
The changes made in this hunk pack file content and diff into the inputs if they are not too long. The new code counts the occurrences of `$file_content` and `$file_diff` in the prompt and limits the number of tokens to `options.heavy_token_limits.request_tokens`. This is a good improvement as it allows for more information to be included in the inputs without exceeding the token limit. However, I suggest adding some error handling in case the token count exceeds the limit.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -148,10 +157,15 @@ export const handleReviewComment = async (
if (inputs.diff.length === 0) {
inputs.diff = file_diff
}
+ // count occurrences of $file_diff in prompt
+ const file_diff_count =
+ prompts.summarize_file_diff.split('$file_diff').length - 1
const file_diff_tokens = tokenizer.get_token_count(file_diff)
if (
- file_diff_tokens < options.heavy_token_limits.extra_content_tokens
+ tokens + file_diff_tokens * file_diff_count <=
+ options.heavy_token_limits.request_tokens
) {
+ tokens += file_diff_tokens * file_diff_count
inputs.file_diff = file_diff
}
} | :robot: OpenAI
This hunk also packs file diff into the inputs if it's not too long. Similar to the previous hunk, the new code counts the occurrences of `$file_diff` in the prompt and limits the number of tokens to `options.heavy_token_limits.request_tokens`. Again, this is a good improvement, but I suggest adding error handling in case the token count exceeds the limit.
Overall, these changes seem reasonable and well-implemented. However, I suggest adding some error handling to prevent exceeding the token limit.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -162,49 +162,57 @@ ${hunks.old_hunk}
file_diff: string
): Promise<[string, string] | null> => {
const ins = inputs.clone()
+ if (file_diff.length === 0) {
+ core.warning(`summarize: file_diff is empty, skip ${filename}`)
+ return null
+ }
+
ins.filename = filename
+ // render prompt based on inputs so far
+ let tokens = tokenizer.get_token_count(
+ prompts.render_summarize_file_diff(ins)
+ )
+
+ const diff_tokens = tokenizer.get_token_count(file_diff)
+ if (tokens + diff_tokens > options.light_token_limits.request_tokens) {
+ core.info(`summarize: diff tokens exceeds limit, skip ${filename}`)
+ return null
+ }
+ ins.file_diff = file_diff
+ tokens += file_diff.length
+
+ // optionally pack file_content
if (file_content.length > 0) {
+ // count occurrences of $file_content in prompt
+ const file_content_count =
+ prompts.summarize_file_diff.split('$file_content').length - 1
+ const file_content_tokens = tokenizer.get_token_count(file_content)
if (
- tokenizer.get_token_count(file_content) <
- options.light_token_limits.extra_content_tokens
+ tokens + file_content_tokens * file_content_count <=
+ options.light_token_limits.request_tokens
) {
+ tokens += file_content_tokens * file_content_count
ins.file_content = file_content
}
}
+ // summarize content
+ try {
+ const [summarize_resp] = await lightBot.chat(
+ prompts.render_summarize_file_diff(ins),
+ {}
+ )
- if (file_diff.length > 0) {
- ins.file_diff = file_diff
- }
-
- // Check if there is either file content or file diff to process
- if (ins.file_content || ins.file_diff) {
- const file_diff_tokens = tokenizer.get_token_count(file_diff)
-
- if (
- !ins.file_diff ||
- file_diff_tokens < options.light_token_limits.extra_content_tokens
- ) {
- // summarize content
- try {
- const [summarize_resp] = await lightBot.chat(
- prompts.render_summarize_file_diff(ins),
- {}
- )
-
- if (!summarize_resp) {
- core.info('summarize: nothing obtained from openai')
- return null
- } else {
- return [filename, summarize_resp]
- }
- } catch (error) {
- core.warning(`summarize: error from openai: ${error}`)
- return null
- }
+ if (!summarize_resp) {
+ core.info('summarize: nothing obtained from openai')
+ return null
+ } else {
+ return [filename, summarize_resp]
}
+ } catch (error) {
+ core.warning(`summarize: error from openai: ${error}`)
+ return null
}
- return null
} | :robot: OpenAI
The changes made in this hunk look good to me. However, I noticed that the `file contents cannot be provided` message is still present in line 164. Is it intentional? If not, it should be removed.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -155,100 +155,117 @@ ${hunks.old_hunk}
file => file !== null
) as [string, string, string, [number, number, string][]][]
| :robot: OpenAI
It seems like the `files_to_review` variable is not being used anymore. Is it safe to remove this code block?
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -155,100 +155,117 @@ ${hunks.old_hunk}
file => file !== null
) as [string, string, string, [number, number, string][]][]
- if (files_to_review.length > 0) {
- const generateSummary = async (
- filename: string,
- file_content: string,
- file_diff: string
- ): Promise<[string, string] | null> => {
- const ins = inputs.clone()
- ins.filename = filename
-
- if (file_content.length > 0) {
- if (
- tokenizer.get_token_count(file_content) <
- options.light_token_limits.extra_content_tokens
- ) {
- ins.file_content = file_content
- }
- }
+ if (files_to_review.length === 0) {
+ core.error(`Skipped: no files to review`)
+ return
+ } | :robot: OpenAI
It would be helpful to log a warning message when there are no files to review, so that users can quickly identify if something went wrong.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -203,6 +203,8 @@ ${tag}`
core.warning(
`Failed to post review comment, for ${path}:${start_line}-${end_line}: ${e}`
)
+ // throw error
+ throw e
} | :robot: OpenAI
It's generally not a good idea to throw an error in the catch block as it can lead to unexpected behavior. Instead, you should log the error and handle it gracefully. You can remove line 207 and replace lines 203-206 with the following code:
```suggestion
203: core.warning(
204: `Failed to post review comment, for ${path}:${start_line}-${end_line}: ${e}`
205: )
206: return
```
This will log the error and exit the function gracefully without throwing an error.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -155,100 +155,117 @@ ${hunks.old_hunk}
file => file !== null
) as [string, string, string, [number, number, string][]][]
- if (files_to_review.length > 0) {
- const generateSummary = async (
- filename: string,
- file_content: string,
- file_diff: string
- ): Promise<[string, string] | null> => {
- const ins = inputs.clone()
- ins.filename = filename
-
- if (file_content.length > 0) {
- if (
- tokenizer.get_token_count(file_content) <
- options.light_token_limits.extra_content_tokens
- ) {
- ins.file_content = file_content
- }
- }
+ if (files_to_review.length === 0) {
+ core.error(`Skipped: no files to review`)
+ return
+ }
- if (file_diff.length > 0) {
- ins.file_diff = file_diff
- }
+ const summaries_failed: string[] = []
+ const do_summary = async (
+ filename: string,
+ file_content: string,
+ file_diff: string
+ ): Promise<[string, string] | null> => {
+ const ins = inputs.clone()
+ if (file_diff.length === 0) {
+ core.warning(`summarize: file_diff is empty, skip ${filename}`)
+ summaries_failed.push(`${filename} (empty diff)`)
+ return null
+ }
- // Check if there is either file content or file diff to process
- if (ins.file_content || ins.file_diff) {
- const file_diff_tokens = tokenizer.get_token_count(file_diff)
+ ins.filename = filename
+ // render prompt based on inputs so far
+ let tokens = tokenizer.get_token_count(
+ prompts.render_summarize_file_diff(ins)
+ )
- if (
- !ins.file_diff ||
- file_diff_tokens < options.light_token_limits.extra_content_tokens
- ) {
- // summarize content
- try {
- const [summarize_resp] = await lightBot.chat(
- prompts.render_summarize_file_diff(ins),
- {}
- )
-
- if (!summarize_resp) {
- core.info('summarize: nothing obtained from openai')
- return null
- } else {
- return [filename, summarize_resp]
- }
- } catch (error) {
- core.warning(`summarize: error from openai: ${error}`)
- return null
- }
- }
- }
+ const diff_tokens = tokenizer.get_token_count(file_diff)
+ if (tokens + diff_tokens > options.light_token_limits.request_tokens) {
+ core.info(`summarize: diff tokens exceeds limit, skip ${filename}`)
+ summaries_failed.push(`${filename} (diff tokens exceeds limit)`)
return null
}
- const summaryPromises = []
- const skipped_files_to_summarize = []
- for (const [filename, file_content, file_diff] of files_to_review) {
+ ins.file_diff = file_diff
+ tokens += file_diff.length
+
+ // optionally pack file_content
+ if (file_content.length > 0) {
+ // count occurrences of $file_content in prompt
+ const file_content_count =
+ prompts.summarize_file_diff.split('$file_content').length - 1
+ const file_content_tokens = tokenizer.get_token_count(file_content)
if (
- options.max_files_to_summarize <= 0 ||
- summaryPromises.length < options.max_files_to_summarize
+ tokens + file_content_tokens * file_content_count <=
+ options.light_token_limits.request_tokens
) {
- summaryPromises.push(
- openai_concurrency_limit(async () =>
- generateSummary(filename, file_content, file_diff)
- )
- )
+ tokens += file_content_tokens * file_content_count
+ ins.file_content = file_content
+ }
+ }
+ // summarize content
+ try {
+ const [summarize_resp] = await lightBot.chat(
+ prompts.render_summarize_file_diff(ins),
+ {}
+ )
+
+ if (!summarize_resp) {
+ core.info('summarize: nothing obtained from openai')
+ summaries_failed.push(`${filename} (nothing obtained from openai)`)
+ return null
} else {
- skipped_files_to_summarize.push(filename)
+ return [filename, summarize_resp]
}
+ } catch (error) {
+ core.warning(`summarize: error from openai: ${error}`)
+ summaries_failed.push(`${filename} (error from openai: ${error})`)
+ return null
}
+ } | :robot: OpenAI
The `do_summary` function has been updated to include file content and diff in the inputs if they are not too long. However, it seems like the check for file_content.length > 0 on line 193 is redundant since it is already checked on line 182.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -155,100 +155,117 @@ ${hunks.old_hunk}
file => file !== null
) as [string, string, string, [number, number, string][]][]
- if (files_to_review.length > 0) {
- const generateSummary = async (
- filename: string,
- file_content: string,
- file_diff: string
- ): Promise<[string, string] | null> => {
- const ins = inputs.clone()
- ins.filename = filename
-
- if (file_content.length > 0) {
- if (
- tokenizer.get_token_count(file_content) <
- options.light_token_limits.extra_content_tokens
- ) {
- ins.file_content = file_content
- }
- }
+ if (files_to_review.length === 0) {
+ core.error(`Skipped: no files to review`)
+ return
+ }
- if (file_diff.length > 0) {
- ins.file_diff = file_diff
- }
+ const summaries_failed: string[] = []
+ const do_summary = async (
+ filename: string,
+ file_content: string,
+ file_diff: string
+ ): Promise<[string, string] | null> => {
+ const ins = inputs.clone()
+ if (file_diff.length === 0) {
+ core.warning(`summarize: file_diff is empty, skip ${filename}`)
+ summaries_failed.push(`${filename} (empty diff)`)
+ return null
+ }
- // Check if there is either file content or file diff to process
- if (ins.file_content || ins.file_diff) {
- const file_diff_tokens = tokenizer.get_token_count(file_diff)
+ ins.filename = filename
+ // render prompt based on inputs so far
+ let tokens = tokenizer.get_token_count(
+ prompts.render_summarize_file_diff(ins)
+ )
- if (
- !ins.file_diff ||
- file_diff_tokens < options.light_token_limits.extra_content_tokens
- ) {
- // summarize content
- try {
- const [summarize_resp] = await lightBot.chat(
- prompts.render_summarize_file_diff(ins),
- {}
- )
-
- if (!summarize_resp) {
- core.info('summarize: nothing obtained from openai')
- return null
- } else {
- return [filename, summarize_resp]
- }
- } catch (error) {
- core.warning(`summarize: error from openai: ${error}`)
- return null
- }
- }
- }
+ const diff_tokens = tokenizer.get_token_count(file_diff)
+ if (tokens + diff_tokens > options.light_token_limits.request_tokens) {
+ core.info(`summarize: diff tokens exceeds limit, skip ${filename}`)
+ summaries_failed.push(`${filename} (diff tokens exceeds limit)`)
return null
} | :robot: OpenAI
It might be better to throw an error instead of returning null when the diff tokens exceed the limit. This way, the user can be notified immediately that there was an issue with the input.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -155,100 +155,117 @@ ${hunks.old_hunk}
file => file !== null
) as [string, string, string, [number, number, string][]][]
- if (files_to_review.length > 0) {
- const generateSummary = async (
- filename: string,
- file_content: string,
- file_diff: string
- ): Promise<[string, string] | null> => {
- const ins = inputs.clone()
- ins.filename = filename
-
- if (file_content.length > 0) {
- if (
- tokenizer.get_token_count(file_content) <
- options.light_token_limits.extra_content_tokens
- ) {
- ins.file_content = file_content
- }
- }
+ if (files_to_review.length === 0) {
+ core.error(`Skipped: no files to review`)
+ return
+ }
- if (file_diff.length > 0) {
- ins.file_diff = file_diff
- }
+ const summaries_failed: string[] = []
+ const do_summary = async (
+ filename: string,
+ file_content: string,
+ file_diff: string
+ ): Promise<[string, string] | null> => {
+ const ins = inputs.clone()
+ if (file_diff.length === 0) {
+ core.warning(`summarize: file_diff is empty, skip ${filename}`)
+ summaries_failed.push(`${filename} (empty diff)`)
+ return null
+ }
- // Check if there is either file content or file diff to process
- if (ins.file_content || ins.file_diff) {
- const file_diff_tokens = tokenizer.get_token_count(file_diff)
+ ins.filename = filename
+ // render prompt based on inputs so far
+ let tokens = tokenizer.get_token_count(
+ prompts.render_summarize_file_diff(ins)
+ )
- if (
- !ins.file_diff ||
- file_diff_tokens < options.light_token_limits.extra_content_tokens
- ) {
- // summarize content
- try {
- const [summarize_resp] = await lightBot.chat(
- prompts.render_summarize_file_diff(ins),
- {}
- )
-
- if (!summarize_resp) {
- core.info('summarize: nothing obtained from openai')
- return null
- } else {
- return [filename, summarize_resp]
- }
- } catch (error) {
- core.warning(`summarize: error from openai: ${error}`)
- return null
- }
- }
- }
+ const diff_tokens = tokenizer.get_token_count(file_diff)
+ if (tokens + diff_tokens > options.light_token_limits.request_tokens) {
+ core.info(`summarize: diff tokens exceeds limit, skip ${filename}`)
+ summaries_failed.push(`${filename} (diff tokens exceeds limit)`)
return null
}
- const summaryPromises = []
- const skipped_files_to_summarize = []
- for (const [filename, file_content, file_diff] of files_to_review) {
+ ins.file_diff = file_diff
+ tokens += file_diff.length
+
+ // optionally pack file_content
+ if (file_content.length > 0) {
+ // count occurrences of $file_content in prompt
+ const file_content_count =
+ prompts.summarize_file_diff.split('$file_content').length - 1
+ const file_content_tokens = tokenizer.get_token_count(file_content)
if (
- options.max_files_to_summarize <= 0 ||
- summaryPromises.length < options.max_files_to_summarize
+ tokens + file_content_tokens * file_content_count <=
+ options.light_token_limits.request_tokens
) {
- summaryPromises.push(
- openai_concurrency_limit(async () =>
- generateSummary(filename, file_content, file_diff)
- )
- )
+ tokens += file_content_tokens * file_content_count
+ ins.file_content = file_content
+ }
+ }
+ // summarize content | :robot: OpenAI
The logic for packing file content could be simplified by using a single if statement instead of nesting another if statement inside.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 137 | coderabbitai | github-actions[bot] | @@ -155,100 +155,117 @@ ${hunks.old_hunk}
file => file !== null
) as [string, string, string, [number, number, string][]][]
- if (files_to_review.length > 0) {
- const generateSummary = async (
- filename: string,
- file_content: string,
- file_diff: string
- ): Promise<[string, string] | null> => {
- const ins = inputs.clone()
- ins.filename = filename
-
- if (file_content.length > 0) {
- if (
- tokenizer.get_token_count(file_content) <
- options.light_token_limits.extra_content_tokens
- ) {
- ins.file_content = file_content
- }
- }
+ if (files_to_review.length === 0) {
+ core.error(`Skipped: no files to review`)
+ return
+ }
- if (file_diff.length > 0) {
- ins.file_diff = file_diff
- }
+ const summaries_failed: string[] = []
+ const do_summary = async (
+ filename: string,
+ file_content: string,
+ file_diff: string
+ ): Promise<[string, string] | null> => {
+ const ins = inputs.clone()
+ if (file_diff.length === 0) {
+ core.warning(`summarize: file_diff is empty, skip ${filename}`)
+ summaries_failed.push(`${filename} (empty diff)`)
+ return null
+ }
- // Check if there is either file content or file diff to process
- if (ins.file_content || ins.file_diff) {
- const file_diff_tokens = tokenizer.get_token_count(file_diff)
+ ins.filename = filename
+ // render prompt based on inputs so far
+ let tokens = tokenizer.get_token_count(
+ prompts.render_summarize_file_diff(ins)
+ )
- if (
- !ins.file_diff ||
- file_diff_tokens < options.light_token_limits.extra_content_tokens
- ) {
- // summarize content
- try {
- const [summarize_resp] = await lightBot.chat(
- prompts.render_summarize_file_diff(ins),
- {}
- )
-
- if (!summarize_resp) {
- core.info('summarize: nothing obtained from openai')
- return null
- } else {
- return [filename, summarize_resp]
- }
- } catch (error) {
- core.warning(`summarize: error from openai: ${error}`)
- return null
- }
- }
- }
+ const diff_tokens = tokenizer.get_token_count(file_diff)
+ if (tokens + diff_tokens > options.light_token_limits.request_tokens) {
+ core.info(`summarize: diff tokens exceeds limit, skip ${filename}`)
+ summaries_failed.push(`${filename} (diff tokens exceeds limit)`)
return null
}
- const summaryPromises = []
- const skipped_files_to_summarize = []
- for (const [filename, file_content, file_diff] of files_to_review) {
+ ins.file_diff = file_diff
+ tokens += file_diff.length
+
+ // optionally pack file_content
+ if (file_content.length > 0) {
+ // count occurrences of $file_content in prompt
+ const file_content_count =
+ prompts.summarize_file_diff.split('$file_content').length - 1
+ const file_content_tokens = tokenizer.get_token_count(file_content)
if (
- options.max_files_to_summarize <= 0 ||
- summaryPromises.length < options.max_files_to_summarize
+ tokens + file_content_tokens * file_content_count <=
+ options.light_token_limits.request_tokens
) {
- summaryPromises.push(
- openai_concurrency_limit(async () =>
- generateSummary(filename, file_content, file_diff)
- )
- )
+ tokens += file_content_tokens * file_content_count
+ ins.file_content = file_content
+ }
+ }
+ // summarize content
+ try {
+ const [summarize_resp] = await lightBot.chat(
+ prompts.render_summarize_file_diff(ins),
+ {}
+ )
+
+ if (!summarize_resp) {
+ core.info('summarize: nothing obtained from openai')
+ summaries_failed.push(`${filename} (nothing obtained from openai)`)
+ return null
} else {
- skipped_files_to_summarize.push(filename)
+ return [filename, summarize_resp]
}
+ } catch (error) {
+ core.warning(`summarize: error from openai: ${error}`)
+ summaries_failed.push(`${filename} (error from openai: ${error})`)
+ return null
}
+ }
+
+ const summaryPromises = []
+ const skipped_files_to_summarize = []
+ for (const [filename, file_content, file_diff] of files_to_review) {
+ if (
+ options.max_files_to_summarize <= 0 ||
+ summaryPromises.length < options.max_files_to_summarize
+ ) {
+ summaryPromises.push(
+ openai_concurrency_limit(async () =>
+ do_summary(filename, file_content, file_diff)
+ )
+ )
+ } else {
+ skipped_files_to_summarize.push(filename)
+ }
+ }
- const summaries = (await Promise.all(summaryPromises)).filter(
- summary => summary !== null
- ) as [string, string][]
+ const summaries = (await Promise.all(summaryPromises)).filter(
+ summary => summary !== null
+ ) as [string, string][]
| :robot: OpenAI
Instead of filtering out null values from the summaries array, it might be better to use Promise.allSettled() to ensure that all promises are resolved before continuing. This way, any errors that occur during the promise chain will be caught and logged.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 134 | coderabbitai | github-actions[bot] | @@ -256,7 +270,7 @@ ${COMMENT_REPLY_TAG}
(comment: any) =>
comment.path === path &&
comment.body !== '' &&
- ((comment.start_line &&
+ ((comment.start_line !== undefined &&
comment.start_line >= start_line &&
comment.line <= end_line) ||
comment.line === end_line) | :robot: OpenAI
In the changes made to the `commenter.ts` file, there is a typo in line 274. It should be `comment.line <= end_line` instead of `comment.line <= end_line)`. This could cause issues with the logic of the code.
Overall, the changes made to the codebase are good and improve the code review process. However, the typo in line 274 should be fixed to avoid any potential issues.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 134 | coderabbitai | github-actions[bot] | @@ -173,17 +173,31 @@ ${tag}`
core.info(
`Creating new review comment for ${path}:${start_line}-${end_line}: ${message}`
)
- await octokit.pulls.createReviewComment({
- owner: repo.owner,
- repo: repo.repo,
- pull_number,
- body: message,
- commit_id,
- path,
- line: end_line,
- start_line,
- start_side: 'RIGHT'
- })
+ // if start_line is same as end_line, it's a single line comment
+ // otherwise it's a multi-line comment
+ if (start_line === end_line) {
+ await octokit.pulls.createReviewComment({
+ owner: repo.owner,
+ repo: repo.repo,
+ pull_number,
+ body: message,
+ commit_id,
+ path,
+ line: end_line
+ })
+ } else {
+ await octokit.pulls.createReviewComment({
+ owner: repo.owner,
+ repo: repo.repo,
+ pull_number,
+ body: message,
+ commit_id,
+ path,
+ line: end_line,
+ start_line,
+ start_side: 'RIGHT'
+ })
+ }
}
} catch (e) { | :robot: OpenAI
The changes made to the `commenter.ts` file look good. The code now creates either a single-line or multi-line comment based on the start and end lines of the code changes. This will make it easier for reviewers to leave comments on specific lines of code.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 133 | coderabbitai | github-actions[bot] | @@ -200,14 +200,10 @@ inputs:
LGTM!
---
- It's important that <start_line_number_in_new_hunk> and
- <end_line_number_in_new_hunk> for each review must be within
- line number ranges of new_hunks. Don't echo back the
+ It's important that line number ranges for each review must
+ be sub range of line number range of new_hunks. Don't echo back the
code provided to you as the line number range is sufficient to map
- your comment to the relevant code section (within new_hunks)
- in GitHub. Your responses will be recorded as multi-line review
- comments on the GitHub pull request. Markdown format is preferred
- for text and fenced code blocks should be used for code snippets.
+ your comment to the relevant code section in GitHub.
| :robot: OpenAI
The updated instructions emphasize the importance of providing specific line number ranges for each review and suggest using Markdown format for text and fenced code blocks for code suggestions. This is a good practice as it helps reviewers to quickly locate the relevant code sections and understand the suggested changes.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 133 | coderabbitai | github-actions[bot] | @@ -200,14 +200,10 @@ inputs:
LGTM!
---
- It's important that <start_line_number_in_new_hunk> and
- <end_line_number_in_new_hunk> for each review must be within
- line number ranges of new_hunks. Don't echo back the
+ It's important that line number ranges for each review must
+ be sub range of line number range of new_hunks. Don't echo back the
code provided to you as the line number range is sufficient to map
- your comment to the relevant code section (within new_hunks)
- in GitHub. Your responses will be recorded as multi-line review
- comments on the GitHub pull request. Markdown format is preferred
- for text and fenced code blocks should be used for code snippets.
+ your comment to the relevant code section in GitHub.
Reflect on the provided code at least 3 times and identify any
bug risks or provide improvement suggestions in these changes. | :robot: OpenAI
It's great to see that the instructions encourage reviewers to reflect on the provided code at least three times and identify any bug risks or provide improvement suggestions in these changes. This will help ensure that the code changes are thoroughly reviewed and any potential issues are identified and addressed before merging the changes.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -253,8 +253,8 @@ ${COMMENT_REPLY_TAG}
return comments.filter(
(comment: any) =>
comment.path === path &&
- comment.start_line === start_line &&
- comment.line === end_line &&
+ comment.start_line >= start_line &&
+ comment.line <= end_line && | :robot: OpenAI
The new code in this hunk is also an improvement over the old one. It now filters comments based on a range of start and end lines instead of just a single line number. This will make the filtering more accurate. Great work!
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -120,14 +120,28 @@ export const codeReview = async (
const patches: [number, number, string][] = []
for (const patch of split_patch(file.patch)) {
const patch_lines = patch_start_end_line(patch)
- if (
- !patch_lines ||
- patch_lines.start_line === -1 ||
- patch_lines.end_line === -1
- ) {
+ if (!patch_lines) {
+ continue
+ }
+ const hunks = parse_hunk(patch)
+ if (!hunks) {
continue
}
- patches.push([patch_lines.start_line, patch_lines.end_line, patch])
+ const hunks_str = `old_hunk:
+\`\`\`
+${hunks.old_hunk}
+\`\`\`
+--- | :robot: OpenAI
The changes made here seem reasonable. The new code adds the ability to parse hunks and include old and new code hunks with line numbers in the review comments. This should make it easier for reviewers to understand the changes being made.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -120,14 +120,28 @@ export const codeReview = async (
const patches: [number, number, string][] = []
for (const patch of split_patch(file.patch)) {
const patch_lines = patch_start_end_line(patch)
- if (
- !patch_lines ||
- patch_lines.start_line === -1 ||
- patch_lines.end_line === -1
- ) {
+ if (!patch_lines) {
continue
}
- patches.push([patch_lines.start_line, patch_lines.end_line, patch])
+ const hunks = parse_hunk(patch)
+ if (!hunks) {
+ continue
+ }
+ const hunks_str = `old_hunk:
+\`\`\`
+${hunks.old_hunk}
+\`\`\`
+---
+new_hunk:
+\`\`\`
+${hunks.new_hunk}
+\`\`\`
+`
+ patches.push([
+ patch_lines.new_hunk.start_line,
+ patch_lines.new_hunk.end_line,
+ hunks_str
+ ])
}
if (patches.length > 0) {
return [file.filename, file_content, file_diff, patches] | :robot: OpenAI
The changes made in this hunk seem to be adding a new function `parse_hunk` which parses the hunks and includes them in patches. The code also skips sending comment chains if they exceed token limits. However, I noticed that the condition on line 123 has been changed from checking if `patch_lines.start_line === -1` to `!patch_lines`. This could potentially cause issues as it may skip valid patches. Can you please double-check this change and ensure that it is correct?
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -348,6 +372,17 @@ ${
} else {
comment_chain = ''
}
+ // check comment_chain tokens and skip if too long
+ const comment_chain_tokens = tokenizer.get_token_count(comment_chain)
+ if (
+ comment_chain_tokens >
+ options.heavy_token_limits.extra_content_tokens
+ ) {
+ core.info(
+ `skip sending comment chain of file: ${ins.filename} due to token count: ${comment_chain_tokens}`
+ )
+ comment_chain = ''
+ }
} catch (e: unknown) {
if (e instanceof ChatGPTError) {
core.warning( | :robot: OpenAI
The changes made in this hunk seem reasonable. The code now includes the `comment_chain` in the patches and checks the token count of `comment_chain` before sending it. This will make it easier for reviewers to see the existing review comments in the context of the changes. However, I noticed that the variable `ins` is not defined in this file. Is it defined elsewhere? If not, it needs to be defined or imported.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -356,10 +391,7 @@ ${
}
}
ins.patches += `
-${start_line}-${end_line}:
-\`\`\`diff
${patch}
-\`\`\`
`
if (comment_chain !== '') {
ins.patches += ` | :robot: OpenAI
In the `send_review_comment` function, you are appending the `comment_chain` string to the `ins.patches` string. However, it's not clear what the purpose of the `ins.patches` string is or how it's being used. Can you provide some comments or documentation to explain its usage?
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -484,21 +516,74 @@ const split_patch = (patch: string | null | undefined): string[] => {
const patch_start_end_line = (
patch: string
-): {start_line: number; end_line: number} | null => {
+): {
+ old_hunk: {start_line: number; end_line: number}
+ new_hunk: {start_line: number; end_line: number}
+} | null => {
const pattern = /(^@@ -(\d+),(\d+) \+(\d+),(\d+) @@)/gm
const match = pattern.exec(patch)
if (match) {
- const begin = parseInt(match[4])
- const diff = parseInt(match[5])
+ const old_begin = parseInt(match[2])
+ const old_diff = parseInt(match[3])
+ const new_begin = parseInt(match[4])
+ const new_diff = parseInt(match[5])
return {
- start_line: begin,
- end_line: begin + diff - 1
+ old_hunk: {
+ start_line: old_begin,
+ end_line: old_begin + old_diff - 1
+ },
+ new_hunk: {
+ start_line: new_begin,
+ end_line: new_begin + new_diff - 1
+ }
}
} else {
return null
}
}
+const parse_hunk = (
+ hunk: string
+): {old_hunk: string; new_hunk: string} | null => {
+ const hunkInfo = patch_start_end_line(hunk)
+ if (!hunkInfo) {
+ return null
+ }
+
+ const old_hunk_lines: string[] = []
+ const new_hunk_lines: string[] = []
+
+ let old_line = hunkInfo.old_hunk.start_line
+ let new_line = hunkInfo.new_hunk.start_line
+
+ const lines = hunk.split('\n').slice(1) // Skip the @@ line
+
+ // Remove the last line if it's empty
+ if (lines[lines.length - 1] === '') {
+ lines.pop()
+ }
+
+ lines.forEach(line => {
+ if (line.startsWith('-')) {
+ old_hunk_lines.push(`${old_line}: ${line.substring(1)}`)
+ old_line++
+ } else if (line.startsWith('+')) {
+ new_hunk_lines.push(`${new_line}: ${line.substring(1)}`)
+ new_line++
+ } else {
+ old_hunk_lines.push(`${old_line}: ${line}`)
+ new_hunk_lines.push(`${new_line}: ${line}`)
+ old_line++
+ new_line++
+ }
+ })
+
+ return {
+ old_hunk: old_hunk_lines.join('\n'),
+ new_hunk: new_hunk_lines.join('\n')
+ }
+} | :robot: OpenAI
The `parse_hunk` function is overly complex and could be simplified. Specifically, the logic for handling added and removed lines can be combined into a single loop. Additionally, the `Review` type is defined but never used.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -171,7 +171,7 @@ ${tag}`
if (!found) {
core.info(
- `Creating new review comment for ${path}:${end_line}: ${message}`
+ `Creating new review comment for ${path}:${start_line}-${end_line}: ${message}`
) | :robot: OpenAI
The `try-catch` block in this function is not handling errors properly. If an error occurs while creating a new review comment, the catch block only logs the error message as a warning and continues with the execution of the function. This can lead to unexpected behavior and make it difficult to debug issues. It would be better to throw an error or return an error message from the function if an error occurs.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -186,7 +186,9 @@ ${tag}`
})
}
} catch (e) {
- core.warning(`Failed to post review comment: ${e}`)
+ core.warning(
+ `Failed to post review comment, for ${path}:${start_line}-${end_line}: ${e}`
+ )
} | :robot: OpenAI
In the same `createReviewComment` function, the catch block logs a warning message when it fails to post a review comment. However, the warning message only includes the error message and not the path or line numbers that the comment was supposed to be posted on. It would be better to include this information in the warning message to make it easier to debug issues.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -120,14 +120,27 @@ export const codeReview = async (
const patches: [number, number, string][] = []
for (const patch of split_patch(file.patch)) {
const patch_lines = patch_start_end_line(patch)
- if (
- !patch_lines ||
- patch_lines.start_line === -1 ||
- patch_lines.end_line === -1
- ) {
+ if (!patch_lines) {
continue
}
- patches.push([patch_lines.start_line, patch_lines.end_line, patch])
+ const hunks = parse_hunk(patch)
+ if (!hunks) {
+ continue
+ }
+ const hunks_str = `old_hunk:
+\`\`\`
+${hunks.old_hunk}
+\`\`\`
+new_hunk:
+\`\`\`
+${hunks.new_hunk}
+\`\`\`
+`
+ patches.push([
+ patch_lines.new_hunk.start_line,
+ patch_lines.new_hunk.end_line,
+ hunks_str
+ ])
}
if (patches.length > 0) {
return [file.filename, file_content, file_diff, patches] | :robot: OpenAI
The changes made in this hunk seem reasonable. The code now parses hunks and includes old and new code hunks with line numbers, which will make it easier for reviewers to understand the context of the changes. However, I noticed that the function `split_patch` is not defined in this file. Is it defined elsewhere? If not, it needs to be defined or imported.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -120,14 +120,25 @@ export const codeReview = async (
const patches: [number, number, string][] = []
for (const patch of split_patch(file.patch)) {
const patch_lines = patch_start_end_line(patch)
- if (
- !patch_lines ||
- patch_lines.start_line === -1 ||
- patch_lines.end_line === -1
- ) {
+ if (!patch_lines) {
+ continue
+ }
+ const hunks = parse_hunk(patch)
+ if (!hunks) {
continue
}
- patches.push([patch_lines.start_line, patch_lines.end_line, patch])
+ const hunks_str = `\`\`\`old_hunk
+${hunks.old_hunk} | :robot: OpenAI
The new changes look good. However, I suggest renaming the `patches` variable to something more descriptive like `hunks`. It will make the code more readable and easier to understand.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -76,7 +76,7 @@ export class Inputs {
this.filename = filename
this.file_content = file_content
this.file_diff = file_diff
- this.patches = patches
+ this.hunks = patches
this.diff = diff | :robot: OpenAI
The variable name `hunks` seems more appropriate than `patches`. Good change.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -123,8 +123,8 @@ export class Inputs {
if (this.file_diff) {
content = content.replace('$file_diff', this.file_diff)
}
- if (this.patches) {
- content = content.replace('$patches', this.patches)
+ if (this.hunks) {
+ content = content.replace('$patches', this.hunks)
} | :robot: OpenAI
I like the addition of the `hunks` variable, but I think it would be clearer to use the same terminology throughout the codebase. Instead of `$patches`, I suggest using `$hunks`.
129:
Typo: replace 'no diff' with '$diff'.
Overall, these changes seem well thought out and should improve the code review process. However, I recommend adding some error handling to ensure that the `hunks` variable is always populated before being used in line 127. Additionally, it may be worth considering how this change will affect performance, especially for large diffs. Finally, I suggest adding some unit tests to ensure that the new code works as expected.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 132 | coderabbitai | github-actions[bot] | @@ -161,59 +161,76 @@ inputs:
$summary
```
- Here is the content of file `$filename` -
+ Here is the content of file `$filename` with
+ line numbers -
```
$file_content
```
- Format for changes and review comments (if any)
- on line ranges (line numbers in new file) -
- <start_line-end_line>:
- ```diff
- <diff_hunk>
+ Format for changes and review comments (if any) -
+
+
+ ```new_hunk
+ <new code with line numbers>
```
- ```text
+
+ ```old_hunk
+ <old code with line numbers> | :robot: OpenAI
I think this change could introduce a bug because...
```
Please note that the line numbers provided in the review comment must be within the line number ranges of new_hunks. Also, please ensure that your review comments are thorough and thoughtful, identifying any potential issues such as security, logic errors, syntax errors, out of bound errors, data races, consistency, complexity, error handling, typos, grammar, maintainability, performance, and so on.
Let me know if you have any questions or concerns.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -79,7 +79,7 @@ export const codeReview = async (
}
}
- // find patches to review
+ // find hunks to review
const filtered_files_to_review: (
| [string, string, string, [number, number, string][]]
| null | :robot: OpenAI
The variable `filtered_files_to_review` is of type `null | [string, string, string, [number, number, string][]]`. It would be better to use a more descriptive type alias or interface for this type instead of using a tuple. Also, it's not clear what the purpose of this variable is. Can you provide some comments or documentation to explain its usage?
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -120,14 +120,27 @@ export const codeReview = async (
const patches: [number, number, string][] = []
for (const patch of split_patch(file.patch)) {
const patch_lines = patch_start_end_line(patch)
- if (
- !patch_lines ||
- patch_lines.start_line === -1 ||
- patch_lines.end_line === -1
- ) {
+ if (!patch_lines) {
+ continue
+ }
+ const hunks = parse_hunk(patch)
+ if (!hunks) {
continue
}
- patches.push([patch_lines.start_line, patch_lines.end_line, patch])
+ const hunks_str = `
+\`\`\`new_hunk
+${hunks.new_hunk}
+\`\`\`
+
+\`\`\`old_hunk
+${hunks.old_hunk}
+\`\`\`
+`
+ patches.push([
+ patch_lines.new_hunk.start_line,
+ patch_lines.new_hunk.end_line,
+ hunks_str
+ ])
}
if (patches.length > 0) { | :robot: OpenAI
The `split_patch` function is used to split a patch into smaller patches, but it doesn't handle all cases correctly. Specifically, if a patch contains multiple hunks, it will only return the first hunk. This could result in missing review comments or incorrect line numbers. A better approach would be to use a library like `diff2html` to parse the patch and extract the hunks.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -315,6 +328,14 @@ ${
ins.filename = filename
if (file_content.length > 0) {
+ const lines = file_content.split('\n')
+ let line_number = 1
+ file_content = ''
+ for (const line of lines) {
+ file_content += `${line_number}: ${line}
+`
+ line_number += 1
+ }
const file_content_tokens = tokenizer.get_token_count(file_content)
if ( | :robot: OpenAI
The line numbers added to the file content are not accurate because they don't take into account the number of lines added by the previous hunks. This could result in incorrect line numbers in review comments. A better approach would be to keep track of the total number of lines added by previous hunks and add that to the line numbers.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -348,6 +369,17 @@ ${
} else {
comment_chain = ''
}
+ // check comment_chain tokens and skip if too long
+ const comment_chain_tokens = tokenizer.get_token_count(comment_chain)
+ if (
+ comment_chain_tokens >
+ options.heavy_token_limits.extra_content_tokens
+ ) {
+ core.info(
+ `skip sending comment chain of file: ${ins.filename} due to token count: ${comment_chain_tokens}`
+ )
+ comment_chain = ''
+ } | :robot: OpenAI
In the `send_review_comment` function, you are checking the length of the `comment_chain` string and skipping sending if it exceeds a certain token limit. However, it's not clear what the purpose of the `comment_chain` string is or how it's being used. Can you provide some comments or documentation to explain its usage?
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -414,14 +443,14 @@ ${comment_chain}
const reviewPromises = []
const skipped_files_to_review = []
- for (const [filename, file_content, , patches] of files_to_review) {
+ for (const [filename, file_content, , hunks] of files_to_review) {
if (
options.max_files_to_review <= 0 ||
reviewPromises.length < options.max_files_to_review
) {
reviewPromises.push(
openai_concurrency_limit(async () =>
- do_review(filename, file_content, patches)
+ do_review(filename, file_content, hunks)
)
)
} else { | :robot: OpenAI
I noticed that the variable `patches` has been renamed to `hunks` in this section of the code. It would be better to keep the variable names consistent throughout the codebase to avoid confusion.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -120,14 +120,27 @@ export const codeReview = async (
const patches: [number, number, string][] = []
for (const patch of split_patch(file.patch)) {
const patch_lines = patch_start_end_line(patch)
- if (
- !patch_lines ||
- patch_lines.start_line === -1 ||
- patch_lines.end_line === -1
- ) {
+ if (!patch_lines) {
+ continue
+ }
+ const hunks = parse_hunk(patch)
+ if (!hunks) {
continue
}
- patches.push([patch_lines.start_line, patch_lines.end_line, patch])
+ const hunks_str = `
+\`\`\`new_hunk
+${hunks.new_hunk}
+\`\`\`
+
+\`\`\`old_hunk
+${hunks.old_hunk}
+\`\`\`
+`
+ patches.push([
+ patch_lines.new_hunk.start_line,
+ patch_lines.new_hunk.end_line,
+ hunks_str
+ ])
} | :robot: OpenAI
The new format for displaying hunks and patches looks good. However, I noticed that the `patches` variable is now being used to store an array of `hunks`. This could be confusing for someone reading the code in the future. Consider renaming the variable to something more descriptive like `hunks_to_review`.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -484,21 +505,74 @@ const split_patch = (patch: string | null | undefined): string[] => {
const patch_start_end_line = (
patch: string
-): {start_line: number; end_line: number} | null => {
+): {
+ old_hunk: {start_line: number; end_line: number}
+ new_hunk: {start_line: number; end_line: number}
+} | null => {
const pattern = /(^@@ -(\d+),(\d+) \+(\d+),(\d+) @@)/gm
const match = pattern.exec(patch)
if (match) {
- const begin = parseInt(match[4])
- const diff = parseInt(match[5])
+ const old_begin = parseInt(match[2])
+ const old_diff = parseInt(match[3])
+ const new_begin = parseInt(match[4])
+ const new_diff = parseInt(match[5])
return {
- start_line: begin,
- end_line: begin + diff - 1
+ old_hunk: {
+ start_line: old_begin,
+ end_line: old_begin + old_diff - 1
+ },
+ new_hunk: {
+ start_line: new_begin,
+ end_line: new_begin + new_diff - 1
+ }
}
} else {
return null
}
}
+const parse_hunk = (
+ hunk: string
+): {old_hunk: string; new_hunk: string} | null => {
+ const hunkInfo = patch_start_end_line(hunk)
+ if (!hunkInfo) {
+ return null
+ }
+
+ const old_hunk_lines: string[] = []
+ const new_hunk_lines: string[] = []
+
+ let old_line = hunkInfo.old_hunk.start_line
+ let new_line = hunkInfo.new_hunk.start_line
+
+ const lines = hunk.split('\n').slice(1) // Skip the @@ line
+
+ // Remove the last line if it's empty
+ if (lines[lines.length - 1] === '') {
+ lines.pop()
+ }
+
+ lines.forEach(line => {
+ if (line.startsWith('-')) {
+ old_hunk_lines.push(`${line.substring(1)}`)
+ old_line++
+ } else if (line.startsWith('+')) {
+ new_hunk_lines.push(`${new_line}: ${line.substring(1)}`)
+ new_line++
+ } else {
+ old_hunk_lines.push(`${line}`)
+ new_hunk_lines.push(`${new_line}: ${line}`)
+ old_line++
+ new_line++
+ }
+ })
+
+ return {
+ old_hunk: old_hunk_lines.join('\n'),
+ new_hunk: new_hunk_lines.join('\n')
+ }
+} | :robot: OpenAI
The changes made to this section of the code look good. However, I noticed that the `Review` type is no longer being used in the code. Consider removing this type definition to reduce clutter in the codebase.
Overall, the changes look good and seem to improve the readability of the code. However, please address the issues mentioned above before merging the pull request.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -120,14 +120,27 @@ export const codeReview = async (
const patches: [number, number, string][] = []
for (const patch of split_patch(file.patch)) {
const patch_lines = patch_start_end_line(patch)
- if (
- !patch_lines ||
- patch_lines.start_line === -1 ||
- patch_lines.end_line === -1
- ) {
+ if (!patch_lines) {
+ continue
+ }
+ const hunks = parse_hunk(patch)
+ if (!hunks) {
continue
}
- patches.push([patch_lines.start_line, patch_lines.end_line, patch])
+ const hunks_str = `
+\`\`\`new_hunk
+${hunks.new_hunk}
+\`\`\`
+
+\`\`\`old_hunk
+${hunks.old_hunk}
+\`\`\`
+` | :robot: OpenAI
The new code adds a `parse_hunk` function that parses hunks and formats them as markdown. However, the function only returns the formatted hunks and not the line numbers of the hunk. It would be helpful to include the line numbers in the return value so that they can be used to create review comments.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -253,9 +255,11 @@ ${COMMENT_REPLY_TAG}
return comments.filter(
(comment: any) =>
comment.path === path &&
- comment.start_line === start_line &&
- comment.line === end_line &&
- comment.body !== ''
+ comment.body !== '' &&
+ ((comment.start_line &&
+ comment.start_line >= start_line &&
+ comment.line <= end_line) ||
+ comment.line === end_line)
)
}
| :robot: OpenAI
In the `findReviewComments` function, the condition for filtering comments based on line numbers seems incorrect. The current condition checks if the start line number is greater than or equal to the given start line number and if the end line number is less than or equal to the given end line number. However, it should check if the start line number is less than or equal to the given end line number and if the end line number is greater than or equal to the given start line number. This will ensure that all comments within the given line number range are returned.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -484,21 +505,74 @@ const split_patch = (patch: string | null | undefined): string[] => {
const patch_start_end_line = (
patch: string
-): {start_line: number; end_line: number} | null => {
+): {
+ old_hunk: {start_line: number; end_line: number}
+ new_hunk: {start_line: number; end_line: number}
+} | null => {
const pattern = /(^@@ -(\d+),(\d+) \+(\d+),(\d+) @@)/gm
const match = pattern.exec(patch)
if (match) {
- const begin = parseInt(match[4])
- const diff = parseInt(match[5])
+ const old_begin = parseInt(match[2])
+ const old_diff = parseInt(match[3])
+ const new_begin = parseInt(match[4])
+ const new_diff = parseInt(match[5])
return {
- start_line: begin,
- end_line: begin + diff - 1
+ old_hunk: {
+ start_line: old_begin,
+ end_line: old_begin + old_diff - 1
+ },
+ new_hunk: {
+ start_line: new_begin,
+ end_line: new_begin + new_diff - 1
+ }
}
} else {
return null
}
}
+const parse_patch = (
+ patch: string
+): {old_hunk: string; new_hunk: string} | null => {
+ const hunkInfo = patch_start_end_line(patch)
+ if (!hunkInfo) {
+ return null
+ }
+
+ const old_hunk_lines: string[] = []
+ const new_hunk_lines: string[] = []
+
+ //let old_line = hunkInfo.old_hunk.start_line
+ let new_line = hunkInfo.new_hunk.start_line
+
+ const lines = patch.split('\n').slice(1) // Skip the @@ line
+
+ // Remove the last line if it's empty
+ if (lines[lines.length - 1] === '') {
+ lines.pop()
+ }
+
+ lines.forEach(line => {
+ if (line.startsWith('-')) {
+ old_hunk_lines.push(`${line.substring(1)}`)
+ //old_line++
+ } else if (line.startsWith('+')) {
+ new_hunk_lines.push(`${new_line}: ${line.substring(1)}`)
+ new_line++
+ } else {
+ old_hunk_lines.push(`${line}`)
+ new_hunk_lines.push(`${new_line}: ${line}`)
+ //old_line++
+ new_line++
+ }
+ })
+
+ return {
+ old_hunk: old_hunk_lines.join('\n'),
+ new_hunk: new_hunk_lines.join('\n')
+ }
+} | :robot: OpenAI
The new implementation of `patch_start_end_line` and `parse_patch` functions seem to be working correctly. However, it would be helpful to add some unit tests to ensure that these functions are working as expected.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -120,14 +120,27 @@ export const codeReview = async (
const patches: [number, number, string][] = []
for (const patch of split_patch(file.patch)) {
const patch_lines = patch_start_end_line(patch)
- if (
- !patch_lines ||
- patch_lines.start_line === -1 ||
- patch_lines.end_line === -1
- ) {
+ if (!patch_lines) {
+ continue
+ }
+ const hunks = parse_patch(patch)
+ if (!hunks) {
continue
}
- patches.push([patch_lines.start_line, patch_lines.end_line, patch])
+ const hunks_str = `
+\`\`\`new_hunk
+${hunks.new_hunk}
+\`\`\`
+
+\`\`\`old_hunk
+${hunks.old_hunk}
+\`\`\`
+`
+ patches.push([
+ patch_lines.new_hunk.start_line,
+ patch_lines.new_hunk.end_line,
+ hunks_str
+ ])
} | :robot: OpenAI
The new implementation of `parse_patches` function seems to be generating a lot of unnecessary string concatenations and template literals. This could potentially impact performance, especially when dealing with large patches. Consider using a more efficient way to generate the `patches` array.
<!-- This is an auto-generated reply by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 132 | coderabbitai | github-actions[bot] | @@ -484,21 +505,74 @@ const split_patch = (patch: string | null | undefined): string[] => {
const patch_start_end_line = (
patch: string
-): {start_line: number; end_line: number} | null => {
+): {
+ old_hunk: {start_line: number; end_line: number}
+ new_hunk: {start_line: number; end_line: number}
+} | null => {
const pattern = /(^@@ -(\d+),(\d+) \+(\d+),(\d+) @@)/gm
const match = pattern.exec(patch)
if (match) {
- const begin = parseInt(match[4])
- const diff = parseInt(match[5])
+ const old_begin = parseInt(match[2])
+ const old_diff = parseInt(match[3])
+ const new_begin = parseInt(match[4])
+ const new_diff = parseInt(match[5])
return {
- start_line: begin,
- end_line: begin + diff - 1
+ old_hunk: {
+ start_line: old_begin,
+ end_line: old_begin + old_diff - 1
+ },
+ new_hunk: {
+ start_line: new_begin,
+ end_line: new_begin + new_diff - 1
+ }
}
} else {
return null
}
}
+const parse_patch = (
+ patch: string
+): {old_hunk: string; new_hunk: string} | null => {
+ const hunkInfo = patch_start_end_line(patch)
+ if (!hunkInfo) {
+ return null
+ }
+
+ const old_hunk_lines: string[] = []
+ const new_hunk_lines: string[] = []
+
+ //let old_line = hunkInfo.old_hunk.start_line
+ let new_line = hunkInfo.new_hunk.start_line
+
+ const lines = patch.split('\n').slice(1) // Skip the @@ line
+
+ // Remove the last line if it's empty
+ if (lines[lines.length - 1] === '') {
+ lines.pop()
+ }
+
+ for (const line of lines) {
+ if (line.startsWith('-')) {
+ old_hunk_lines.push(`${line.substring(1)}`)
+ //old_line++
+ } else if (line.startsWith('+')) {
+ new_hunk_lines.push(`${new_line}: ${line.substring(1)}`)
+ new_line++
+ } else {
+ old_hunk_lines.push(`${line}`)
+ new_hunk_lines.push(`${new_line}: ${line}`)
+ //old_line++
+ new_line++
+ }
+ }
+
+ return {
+ old_hunk: old_hunk_lines.join('\n'),
+ new_hunk: new_hunk_lines.join('\n')
+ }
+} | :robot: OpenAI
In the `patch_start_end_line` and `parse_patch` functions, you are using a lot of magic numbers (e.g. 2, 3, 4, 5, etc.) to extract line numbers from the patch. This makes the code hard to read and understand. Consider using named constants or variables to make the code more readable.
Overall, the changes look good and seem to improve the quality of feedback provided by reviewers. However, I would recommend addressing the issues mentioned above to improve the readability and maintainability of the code.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 131 | coderabbitai | github-actions[bot] | @@ -203,10 +203,7 @@ inputs:
code provided to you as the line number range is sufficient to map
your comment to the relevant code section in GitHub. Your responses
will be recorded as multi-line review comments on the GitHub pull
- request. Markdown format is preferred for your responses. Code
- suggestions must be withing the fenced code blocks with appropriate
- language identifier and you must not use `suggestion` identifier.
-
+ request. Markdown format is preferred for your responses.
Reflect on the provided code at least 3 times to identify any
bug risks or provide improvement suggestions in these diff hunks. | :robot: OpenAI
```diff
@@ -203,10 +203,8 @@ inputs:
code provided to you as the line number range is sufficient to map
your comment to the relevant code section in GitHub. Your responses
will be recorded as multi-line review comments on the GitHub pull
- request. Markdown format is preferred for your responses. Code
- suggestions must be withing the fenced code blocks with appropriate
- language identifier and you must not use `suggestion` identifier.
-
+ request. Markdown format is preferred for your responses. Use inline code formatting (`code`) for code snippets.
- Reflect on the provided code at least 3 times to identify any
+ Provide thorough and thoughtful feedback to identify any
bug risks or provide improvement suggestions in these diff hunks.
```
Please let me know if you have any questions or concerns.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 129 | coderabbitai | github-actions[bot] | @@ -353,7 +353,13 @@ ${chain}
return top_level_comment
}
+ private reviewCommentsCache: Record<number, any[]> = {}
+
async list_review_comments(target: number) {
+ if (this.reviewCommentsCache[target]) {
+ return this.reviewCommentsCache[target]
+ }
+
const all_comments: any[] = []
let page = 1
try { | :robot: OpenAI
```diff
@@ -353,7 +353,13 @@ ${chain}
return top_level_comment
}
+ private reviewCommentsCache: Record<number, any[]> = {}
+
async list_review_comments(target: number) {
+ if (this.reviewCommentsCache[target]) {
+ return this.reviewCommentsCache[target]
+ }
+
const all_comments: any[] = []
let page = 1
try {
```
The changes made to the `list_review_comments` method look good. However, there is a potential bug risk in the implementation of caching. If the cache is not cleared when new comments are added or existing comments are updated, the cached comments may become stale and lead to incorrect behavior. Please make sure to add logic to clear the cache when necessary.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 129 | coderabbitai | github-actions[bot] | @@ -372,6 +378,7 @@ ${chain}
}
}
+ this.reviewCommentsCache[target] = all_comments
return all_comments
} catch (e) {
core.warning(`Failed to list review comments: ${e}`) | :robot: OpenAI
```diff
@@ -372,6 +378,7 @@ ${chain}
}
}
+ this.reviewCommentsCache[target] = all_comments
return all_comments
} catch (e) {
core.warning(`Failed to list review comments: ${e}`)
```
The addition of caching for review comments looks good. However, it would be better to add some error handling logic to handle cases where the cache cannot be set due to an error. For example, if the cache size limit is reached, or if there is an issue with the cache storage mechanism, the code should handle these errors gracefully.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 129 | coderabbitai | github-actions[bot] | @@ -462,7 +469,13 @@ ${chain}
}
}
+ private issueCommentsCache: Record<number, any[]> = {}
+
async list_comments(target: number) {
+ if (this.issueCommentsCache[target]) {
+ return this.issueCommentsCache[target]
+ }
+
const all_comments: any[] = []
let page = 1
try { | :robot: OpenAI
```diff
@@ -462,7 +469,13 @@ ${chain}
}
}
+ private issueCommentsCache: Record<number, any[]> = {}
+
async list_comments(target: number) {
+ if (this.issueCommentsCache[target]) {
+ return this.issueCommentsCache[target]
+ }
+
const all_comments: any[] = []
let page = 1
try {
```
The changes made to the `list_comments` method look good. However, there is a potential bug risk in the implementation of caching. If the cache is not cleared when new comments are added or existing comments are updated, the cached comments may become stale and lead to incorrect behavior. Please make sure to add logic to clear the cache when necessary.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 129 | coderabbitai | github-actions[bot] | @@ -481,6 +494,7 @@ ${chain}
}
}
+ this.issueCommentsCache[target] = all_comments
return all_comments
} catch (e: unknown) {
if (e instanceof ChatGPTError) { | :robot: OpenAI
```diff
@@ -481,6 +494,7 @@ ${chain}
}
}
+ this.issueCommentsCache[target] = all_comments
return all_comments
} catch (e: unknown) {
if (e instanceof ChatGPTError) {
```
The addition of caching for issue comments looks good. However, it would be better to add some error handling logic to handle cases where the cache cannot be set due to an error. For example, if the cache size limit is reached, or if there is an issue with the cache storage mechanism, the code should handle these errors gracefully.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 123 | coderabbitai | github-actions[bot] | @@ -89,11 +89,7 @@ inputs:
default: |
You are `@openai` (aka `github-actions[bot]`), a language model
trained by OpenAI. You have been designed to act as a highly
- experienced software engineer today. Your main task is to review
- code and documentation, provide suggestions, and write new code
- or documentation when requested. Please ensure that your responses
- are focused on assisting with code and documentation concerns,
- following best practices and industry standards.
+ experienced software engineer today.
summarize_file_diff:
required: false
description: 'The prompt for the whole pull request' | :robot: OpenAI
```diff
@@ -89,11 +89,7 @@ inputs:
default: |
You are `@openai` (aka `github-actions[bot]`), a language model
trained by OpenAI. You have been designed to act as a highly
- experienced software engineer today. Your main task is to review
- code and documentation, provide suggestions, and write new code
- or documentation when requested. Please ensure that your responses
- are focused on assisting with code and documentation concerns,
- following best practices and industry standards.
+ experienced software engineer today.
summarize_file_diff:
required: false
description: 'The prompt for the whole pull request'
```
This change seems fine to me. It removes unnecessary text and simplifies the instructions.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 123 | coderabbitai | github-actions[bot] | @@ -198,21 +194,11 @@ inputs:
<start_line-end_line>:
<review comment>
---
- <start_line-end_line>:
- <explain why suggestion makes sense>
- ```suggestion
- <replacement code that from start_line, with necessary changes>
- ```
- ---
...
You can comment or suggest code changes for the diff hunks and the
line ranges provided by you should map to the exact line ranges
- provided in the diff hunks. When suggesting a code change, it is
- important that you provide the new code that replaces the entire
- line range in the diff hunk from the beginning, including the context
- lines in the diff hunk. Partial replacements are not acceptable, as
- they will not work with GitHub's code suggestion feature.
+ provided in the diff hunks.
Reflect on the provided code at least 3 times to identify any
bug risks or provide improvement suggestions in these diff hunks. | :robot: OpenAI
```text
The change made in this diff hunk removes the suggestion format for code changes. While this may be intentional, it may also make it harder for users to suggest code changes in a clear and concise manner. Consider providing an alternative format or explanation for how users can suggest code changes.
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 123 | coderabbitai | github-actions[bot] | @@ -294,16 +280,7 @@ inputs:
If the comment contains instructions/requests for you, please comply.
For example, if the comment is asking you to generate documentation
- comments on the code, in your reply please generate the required code
- and provide as fenced code block in markdown.
-
- Any code change suggestion to the diff hunk must be enclosed in fenced code
- blocks with the suggestion identifier and the change must completely
- replace the diff hunk provided to you from the beginning -
- <your comment to the user>
- ```suggestion
- <change>
- ```
+ comments on the code, in your reply please generate the required code.
runs:
using: 'node16'
main: 'dist/index.js' | :robot: OpenAI
```text
The change made in this diff hunk removes the fenced code block requirement for code change suggestions. While this may simplify the process, it may also make it harder to distinguish between regular comments and code change suggestions. Consider keeping the fenced code block requirement or providing an alternative way to distinguish between comments and code change suggestions.
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 122 | coderabbitai | github-actions[bot] | @@ -91,7 +91,9 @@ inputs:
trained by OpenAI. You have been designed to act as a highly
experienced software engineer today. Your main task is to review
code and documentation, provide suggestions, and write new code
- or documentation when requested.
+ or documentation when requested. Please ensure that your responses
+ are focused on assisting with code and documentation concerns,
+ following best practices and industry standards.
summarize_file_diff:
required: false
description: 'The prompt for the whole pull request' | :robot: OpenAI
The new instructions are clear and helpful. However, I suggest rephrasing the sentence "Please ensure that your responses are focused on assisting with code and documentation concerns, following best practices and industry standards" to "Please ensure that your responses focus on assisting with code and documentation concerns and follow best practices and industry standards."
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 122 | coderabbitai | github-actions[bot] | @@ -183,7 +186,7 @@ inputs:
displaying added, removed, and unchanged lines with
"+" or "-" prefixes and surrounding context lines.
- Patches for review are below -
+ Diff hunks for review are below -
$patches
| :robot: OpenAI
It would be better to use the term "diff hunks" instead of "patches" throughout the document to avoid confusion.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 122 | coderabbitai | github-actions[bot] | @@ -229,7 +236,7 @@ inputs:
required: false
description: 'Prompt for comment'
default: |
- A comment was made on a review for a diff patch on file
+ A comment was made on a review for a diff hunk on file
`$filename`. I would like you to follow the instructions
in that comment.
| :robot: OpenAI
Please change the section header from "Prompt for Comment" to "Prompt for Comment on Diff Hunk".
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 122 | coderabbitai | github-actions[bot] | @@ -297,10 +304,11 @@ inputs:
and provide as fenced code block in markdown.
Any code change suggestion to the diff hunk must be enclosed in fenced code
- blocks with the suggestion identifier -
+ blocks with the suggestion identifier and the change must completely
+ replace the diff hunk provided to you from the beginning -
<your comment to the user>
- ```diff
- <suggested diff>
+ ```suggestion
+ <change>
```
runs:
using: 'node16' | :robot: OpenAI
Please change the section header from "Code Change Suggestions" to "Code Change Suggestions for Diff Hunks". Additionally, please clarify that any code change suggestion to the diff hunk must be enclosed in fenced code blocks with the suggestion identifier and the change must completely replace the diff hunk provided to you from the beginning.
Overall, the changes made to `action.yml` are helpful and provide clear instructions for suggesting code changes and reviewing patches. Thank you for your contribution!
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 122 | coderabbitai | github-actions[bot] | @@ -165,15 +167,15 @@ inputs:
$file_content
```
- Below is the format for patches. `---`
- separator is used between patches.
+ Format for changes and review comments on line ranges.
+ `---` separator is used.
<start_line-end_line>:
```diff
<diff_hunk>
```
```text
- <review comments on patch, if any>
+ <review comments on diff_hunk, if any>
```
---
... | :robot: OpenAI
The format for changes and review comments on line ranges is not clear. It would be helpful to provide an example of how to use this format.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 122 | coderabbitai | github-actions[bot] | @@ -198,29 +200,28 @@ inputs:
---
<start_line-end_line>:
<explain why suggestion makes sense>
- ```diff
- <suggested diff>
+ ```suggestion
+ <replacement code that from start_line, with necessary changes>
```
---
- <start_line-end_line>:
- <explain why new code should be included>
- ```<language>
- <new code>
- ```
...
- You can comment or suggest code changes for the patches and the
+ You can comment or suggest code changes for the diff hunks and the
line ranges provided by you should map to the exact line ranges
- provided in the patches.
+ provided in the diff hunks. When suggesting a code change, it is
+ important that you provide the new code that replaces the entire
+ line range in the diff hunk from the beginning, including the context
+ lines in the diff hunk. Partial replacements are not acceptable, as
+ they will not work with GitHub's code suggestion feature.
Reflect on the provided code at least 3 times to identify any
- bug risks or provide improvement suggestions in these patches.
+ bug risks or provide improvement suggestions in these diff hunks.
You will point out potential issues such as security, logic errors,
syntax errors, out of bound errors, data races, consistency,
complexity, error handling, typos, grammar, maintainability,
performance, and so on.
- If there are no issues or suggestions and the patch is acceptable
+ If there are no issues or suggestions and the diff hunk is acceptable
as-is, please include "LGTM!" (exact word) in your short
review comment.
| :robot: OpenAI
When suggesting a code change, it is important that you provide the new code that replaces the entire line range in the diff hunk from the beginning, including the context lines in the diff hunk. Partial replacements are not acceptable, as they will not work with GitHub's code suggestion feature.
Please let me know if you have any questions or concerns about these comments.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 121 | coderabbitai | github-actions[bot] | @@ -213,11 +213,7 @@ inputs:
You can comment or suggest code changes for the patches and the
line ranges provided by you should map to the exact line ranges
- provided in the patches. When suggesting a code change, it is
- important that you provide the new code that replaces the entire
- line range in the patch from the beginning. Partial replacements
- are not acceptable, as they will not work with GitHub's code
- suggestion feature.
+ provided in the patches.
Reflect on the provided code at least 3 times to identify any
bug risks or provide improvement suggestions in these patches. | :robot: OpenAI
I suggest removing the sentence "Partial replacements are not acceptable, as they will not work with GitHub's code suggestion feature." This is no longer applicable since the restriction on partial replacements has been removed.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 121 | coderabbitai | github-actions[bot] | @@ -91,9 +91,7 @@ inputs:
trained by OpenAI. You have been designed to act as a highly
experienced software engineer today. Your main task is to review
code and documentation, provide suggestions, and write new code
- or documentation when requested. Please ensure that your responses
- are focused on assisting with code and documentation concerns,
- following best practices and industry standards.
+ or documentation when requested.
summarize_file_diff:
required: false
description: 'The prompt for the whole pull request' | :robot: OpenAI
I suggest keeping the requirement for responses to follow best practices and industry standards. This ensures that the code review process maintains a high level of quality and consistency.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 121 | coderabbitai | github-actions[bot] | @@ -200,8 +198,8 @@ inputs:
---
<start_line-end_line>:
<explain why suggestion makes sense>
- ```suggestion
- <replacement code that from start_line, with necessary changes>
+ ```diff
+ <suggested diff>
```
---
<start_line-end_line>: | :robot: OpenAI
I suggest changing the suggested diff format from `diff` to `suggestion`. This will make it consistent with the current format used in the file.
```diff
@@ -200,8 +198,8 @@ inputs:
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 121 | coderabbitai | github-actions[bot] | @@ -303,11 +297,10 @@ inputs:
and provide as fenced code block in markdown.
Any code change suggestion to the diff hunk must be enclosed in fenced code
- blocks with the suggestion identifier and the change must completely
- replace the diff hunk provided to you from the beginning -
+ blocks with the suggestion identifier -
<your comment to the user>
- ```suggestion
- <change>
+ ```diff
+ <suggested diff>
```
runs:
using: 'node16' | :robot: OpenAI
I suggest adding an explanation for why suggested diffs should completely replace the diff hunk provided from the beginning. This will help ensure that the suggested changes are clear and complete.
```diff
@@ -303,11 +297,12 @@ inputs:
and provide as fenced code block in markdown.
Any code change suggestion to the diff hunk must be enclosed in fenced code
- blocks with the suggestion identifier and the change must completely
- replace the diff hunk provided to you from the beginning -
+ blocks with the suggestion identifier. It is important that the suggested
+ diff completely replaces the diff hunk provided from the beginning, to
+ ensure clarity and completeness -
<your comment to the user>
```diff
+ <suggested diff>
```
runs:
using: 'node16'
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 120 | coderabbitai | github-actions[bot] | @@ -213,9 +213,11 @@ inputs:
You can comment or suggest code changes for the patches and the
line ranges provided by you should map to the exact line ranges
- provided in the patches. When suggesting a code change, please
- provide the new code that replaces the entire patch from the
- beginning.
+ provided in the patches. When suggesting a code change, it is
+ important that you provide the new code that replaces the entire
+ line range in the patch from the beginning. Partial replacements
+ are not acceptable, as they will not work with GitHub's code
+ suggestion feature.
Reflect on the provided code at least 3 times to identify any
bug risks or provide improvement suggestions in these patches. | :robot: OpenAI
```diff
@@ -213,9 +213,11 @@ inputs:
You can comment or suggest code changes for the patches and the
line ranges provided by you should map to the exact line ranges
- provided in the patches. When suggesting a code change, please
- provide the new code that replaces the entire patch from the
- beginning.
+ provided in the patches. When suggesting a code change, it is
+ important that you provide the new code that replaces the entire
+ line range in the patch from the beginning. Partial replacements
+ are not acceptable, as they will not work with GitHub's code
+ suggestion feature.
Reflect on the provided code at least 3 times to identify any
bug risks or provide improvement suggestions in these patches.
```
This patch looks good to me. It provides clear instructions on how to suggest code changes and emphasizes the importance of thoroughly reviewing the provided code.
Overall, it would be helpful to have more context on what changes were made in the pull request and why they were made. Additionally, it would be good to see more detailed explanations for the suggestions made in the patches.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 120 | coderabbitai | github-actions[bot] | @@ -201,7 +201,7 @@ inputs:
<start_line-end_line>:
<explain why suggestion makes sense>
```suggestion
- <replacement code>
+ <replacement code that completely replaces the line range>
```
---
<start_line-end_line>: | :robot: OpenAI
It would be helpful to include an explanation of why the suggested change makes sense. Additionally, please ensure that the replacement code completely replaces the line range specified in the patch from the beginning. Partial replacements are not acceptable.
```suggestion
<replacement code that completely replaces the line range>
```
<!-- This is an auto-generated reply by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 120 | coderabbitai | github-actions[bot] | @@ -201,7 +201,7 @@ inputs:
<start_line-end_line>:
<explain why suggestion makes sense>
```suggestion
- <replacement code>
+ <replacement code that from start_line, with necessary changes>
```
---
<start_line-end_line>: | :robot: OpenAI
```diff
@@ -201,7 +201,7 @@ inputs:
<start_line-end_line>:
<explain why suggestion makes sense>
```suggestion
- <replacement code>
+ <replacement code that from start_line, with necessary changes>
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 117 | coderabbitai | github-actions[bot] | @@ -134,7 +134,8 @@ ${tag}`
pull_number: number,
commit_id: string,
path: string,
- line: number,
+ start_line: number,
+ end_line: number,
message: string,
tag: string = COMMENT_TAG
) { | :robot: OpenAI
The `Commenter` class has been modified to handle ranges instead of single lines. The `createReviewComment` method call now includes the new `start_line` and `end_line` parameters. However, it seems that the `end_line` parameter is not being used in the method implementation. Please update the implementation to use both `start_line` and `end_line` parameters appropriately.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 117 | coderabbitai | github-actions[bot] | @@ -146,10 +147,17 @@ ${tag}`
// replace comment made by this action
try {
let found = false
- const comments = await this.get_comments_at_line(pull_number, path, line)
+ const comments = await this.get_comments_at_range(
+ pull_number,
+ path,
+ start_line,
+ end_line
+ )
for (const comment of comments) {
if (comment.body.includes(tag)) {
- core.info(`Updating review comment for ${path}:${line}: ${message}`)
+ core.info(
+ `Updating review comment for ${path}:${end_line}: ${message}`
+ )
await octokit.pulls.updateReviewComment({
owner: repo.owner,
repo: repo.repo, | :robot: OpenAI
In the `update_review_comment` method, the logging message still refers to `line` instead of `end_line`. Please update the logging message to reflect the change from `line` to `end_line`.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 117 | coderabbitai | github-actions[bot] | @@ -162,15 +170,19 @@ ${tag}`
}
if (!found) {
- core.info(`Creating new review comment for ${path}:${line}: ${message}`)
+ core.info(
+ `Creating new review comment for ${path}:${end_line}: ${message}`
+ )
await octokit.pulls.createReviewComment({
owner: repo.owner,
repo: repo.repo,
pull_number,
body: message,
commit_id,
path,
- line
+ line: end_line,
+ start_line,
+ start_side: 'RIGHT'
})
}
} catch (e) { | :robot: OpenAI
In the `create_new_review_comment` method, the logging message still refers to `line` instead of `end_line`. Please update the logging message to reflect the change from `line` to `end_line`.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 117 | coderabbitai | github-actions[bot] | @@ -231,24 +243,34 @@ ${COMMENT_REPLY_TAG}
}
}
- async get_comments_at_line(pull_number: number, path: string, line: number) {
+ async get_comments_at_range(
+ pull_number: number,
+ path: string,
+ start_line: number,
+ end_line: number
+ ) {
const comments = await this.list_review_comments(pull_number)
return comments.filter(
(comment: any) =>
- comment.path === path && comment.line === line && comment.body !== ''
+ comment.path === path &&
+ comment.start_line === start_line &&
+ comment.line === end_line &&
+ comment.body !== ''
)
}
- async get_conversation_chains_at_line(
+ async get_conversation_chains_at_range(
pull_number: number,
path: string,
- line: number,
+ start_line: number,
+ end_line: number,
tag = ''
) {
- const existing_comments = await this.get_comments_at_line(
+ const existing_comments = await this.get_comments_at_range(
pull_number,
path,
- line
+ start_line,
+ end_line
)
// find all top most comments
const top_level_comments = [] | :robot: OpenAI
In the `get_comments_at_range` method, the `line` parameter is being compared with `end_line` instead of `start_line`. Please update the comparison to use `start_line` instead of `line`.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 118 | coderabbitai | github-actions[bot] | @@ -207,12 +207,7 @@ inputs:
review comment.
Your responses will be recorded as review comments on the
- pull request. Markdown format is preferred for your responses. Any
- code suggestions that you suggest must be enclosed in fenced code
- blocks with the suggestion identifier -
- ```suggestion
- <code>
- ```
+ pull request. Markdown format is preferred for your responses.
comment:
required: false
description: 'Prompt for comment' | :robot: OpenAI
The updated description of the `comment` input mentions that Markdown format is preferred for responses. However, the previous description also mentioned fenced code blocks with suggestion identifiers for code suggestions. It might be helpful to keep this information in the description as well, since it provides a clear way for contributors to suggest code changes.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 114 | coderabbitai | github-actions[bot] | @@ -7,6 +7,7 @@ import {codeReview} from './review.js'
async function run(): Promise<void> {
const options: Options = new Options(
core.getBooleanInput('debug'),
+ core.getBooleanInput('summary_only'),
core.getInput('max_files_to_summarize'),
core.getInput('max_files_to_review'),
core.getBooleanInput('review_comment_lgtm'), | :robot: OpenAI
The addition of the `summary_only` flag seems fine. However, it is not clear how this flag will be used in the code. It would be helpful to add a comment or documentation explaining how this flag affects the behavior of the code.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 114 | coderabbitai | github-actions[bot] | @@ -37,10 +38,7 @@ async function run(): Promise<void> {
try {
lightBot = new Bot(
options,
- new OpenAIOptions(
- options.openai_light_model,
- options.summary_token_limits
- )
+ new OpenAIOptions(options.openai_light_model, options.light_token_limits)
)
} catch (e: any) {
core.warning( | :robot: OpenAI
It looks like the `summary_token_limits` property has been replaced with `light_token_limits`. Is this intentional? If so, please update the documentation and comments to reflect this change.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 114 | coderabbitai | github-actions[bot] | @@ -53,7 +51,7 @@ async function run(): Promise<void> {
try {
heavyBot = new Bot(
options,
- new OpenAIOptions(options.openai_heavy_model, options.review_token_limits)
+ new OpenAIOptions(options.openai_heavy_model, options.heavy_token_limits)
)
} catch (e: any) {
core.warning( | :robot: OpenAI
Similar to the previous patch, it looks like the `review_token_limits` property has been replaced with `heavy_token_limits`. Please update the documentation and comments to reflect this change.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | others | 114 | coderabbitai | github-actions[bot] | @@ -98,8 +98,28 @@ Thumbs.db
__tests__/runner/*
lib/**/*
+### Tags
+# Ignore tags created by etags, ctags, gtags (GNU global) and cscope
+TAGS
+.TAGS
+!TAGS/
+tags
+.tags
+!tags/
+gtags.files
+GTAGS
+GRTAGS
+GPATH
+GSYMS
+cscope.files
+cscope.out
+cscope.in.out
+cscope.po.out
+tags.temp
+tags.lock
+
+
# Local testing
.env
.secrets
bin/act | :robot: OpenAI
The addition of the section to ignore tags created by various tag generators and temporary files related to these tag generators in `.gitignore` is a good practice. However, it would be better if you could add a comment explaining why these tags are being ignored.
Also, it seems that there are some redundant entries in this section. For example, `TAGS/` and `tags/` are already covered by `TAGS` and `tags`. Similarly, `cscope.files`, `cscope.out`, `cscope.in.out`, and `cscope.po.out` can be combined into a single entry `cscope*`. Finally, `tags.temp` and `tags.lock` can be combined into a single entry `tags.*`.
```diff
@@ -98,8 +98,28 @@ Thumbs.db
__tests__/runner/*
lib/**/*
+### Tags
+# Ignore tags created by etags, ctags, gtags (GNU global) and cscope
+# These tags are generated by various tag generators and are not needed for development
+# More information: https://www.gnu.org/software/global/
+# https://en.wikipedia.org/wiki/Cscope
+TAGS
+.TAGS
+tags
+.tags
+gtags.files
+GTAGS
+GRTAGS
+GPATH
+GSYMS
+cscope*
+
+# Ignore temporary files related to tag generators
+# These files are not needed for development
+tags.*
+
# Local testing
.env
.secrets
bin/act
-
```
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 114 | coderabbitai | github-actions[bot] | @@ -137,7 +137,7 @@ export const handleReviewComment = async (
if (file_content.length > 0) {
const file_content_tokens = tokenizer.get_token_count(file_content)
if (
- file_content_tokens < options.review_token_limits.extra_content_tokens
+ file_content_tokens < options.heavy_token_limits.extra_content_tokens
) {
inputs.file_content = file_content
} | :robot: OpenAI
The `handleReviewComment` function is using the `options.review_token_limits.extra_content_tokens` property to check if the number of tokens in the file content is within limits. However, this property has been renamed to `options.heavy_token_limits.extra_content_tokens` in the pull request. This inconsistency could lead to confusion and errors. It would be better to use the correct property name consistently throughout the codebase.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 114 | coderabbitai | github-actions[bot] | @@ -150,7 +150,7 @@ export const handleReviewComment = async (
}
const file_diff_tokens = tokenizer.get_token_count(file_diff)
if (
- file_diff_tokens < options.review_token_limits.extra_content_tokens
+ file_diff_tokens < options.heavy_token_limits.extra_content_tokens
) {
inputs.file_diff = file_diff
} | :robot: OpenAI
Similar to the previous patch, the `handleReviewComment` function is using the `options.review_token_limits.extra_content_tokens` property to check if the number of tokens in the file diff is within limits. However, this property has been renamed to `options.heavy_token_limits.extra_content_tokens` in the pull request. This inconsistency could lead to confusion and errors. It would be better to use the correct property name consistently throughout the codebase.
<!-- This is an auto-generated comment by OpenAI --> |
ai-pr-reviewer | github_2023 | typescript | 114 | coderabbitai | github-actions[bot] | @@ -147,7 +147,7 @@ export const codeReview = async (
if (file_content.length > 0) {
if (
tokenizer.get_token_count(file_content) <
- options.summary_token_limits.extra_content_tokens
+ options.light_token_limits.extra_content_tokens
) {
ins.file_content = file_content
} | :robot: OpenAI
The `options.summary_token_limits` property has been renamed to `options.light_token_limits`. However, the corresponding check in this patch still uses the old property name. This should be updated to use the new property name.
```diff
@@ -147,7 +147,7 @@ export const codeReview = async (
if (file_content.length > 0) {
if (
tokenizer.get_token_count(file_content) <
- options.summary_token_limits.extra_content_tokens
+ options.light_token_limits.extra_content_tokens
) {
ins.file_content = file_content
}
```
<!-- This is an auto-generated comment by OpenAI --> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.