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

Provide file diff when replying to whole file review comments #64

Merged
merged 10 commits into from
Mar 19, 2023

Conversation

harjotgill
Copy link
Contributor

@harjotgill harjotgill commented Mar 19, 2023

Summary by OpenAI

Release Notes

New Feature: Users can now view file diffs when replying to whole file review comments. The default system message and instructions for code review comments have been updated, and a check for file_content length has been added. These changes aim to improve the user experience and make the code review process smoother.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2023

🤖 OpenAI

Thank you for letting me participate in this code review.

The purpose of this pull request is to add functionality to provide file diffs when replying to whole file review comments, update the default system message and instructions for code review comments, and add a check for file_content length before setting it.

Here is a summary of the changes made to each file:

File Summary
README.md, action.yml The diff adds an image to the README file, updates the default system message, and adds instructions for code review comments.
src/review-comment.ts Adds functionality to provide file diffs when replying to whole file review comments.
src/review.ts Adds a check for file_content length before setting it, and updates the Tips section.

Overall, these changes aim to improve the user experience by providing more context and making the code review process smoother.


Tips:

  • Reply on the review comment left by this bot to ask follow-up questions.
  • Invite the bot into a review conversation by typing @openai in the beginning of the comment.

@coderabbitai coderabbitai deleted a comment from github-actions bot Mar 19, 2023
@coderabbitai coderabbitai deleted a comment from github-actions bot Mar 19, 2023
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@openai Please provide a documentation comment that I can add on top of handleReviewComment method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 OpenAI

Sure, I understand. Here's my response:

@harjotgill Sure, here's a documentation comment that you can add on top of the `handleReviewComment` method:

/**
 * Handles review comments and posts replies to them.
 * @param bot - The bot instance.
 * @param prompts - The prompts instance.
 */
export const handleReviewComment = async (bot: Bot, prompts: Prompts) => {
  // code implementation here
}

Let me know if you need any further assistance.

@coderabbitai coderabbitai deleted a comment from github-actions bot Mar 19, 2023
@coderabbitai coderabbitai deleted a comment from github-actions bot Mar 19, 2023
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@openai Please provide me the bullet point list of all the exported methods in this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 OpenAI

@harjotgill Here is the list of all the exported methods in src/review.ts:

  • codeReview
  • getReviewComment
  • createReviewComment
  • updateReviewComment
  • deleteReviewComment

Let me know if you have any further questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please generate documentation for all the exported methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 OpenAI

Sure, I can generate documentation for all the exported methods. Here is the updated code with documentation comments:

/**
 * Runs a code review on the given file content and diff.
 *
 * @param inputs - The inputs to the code review.
 * @returns A tuple containing the summary and the final response.
 */
export const codeReview = async (
  inputs: Inputs,
): Promise<[string, string] | null> => {
  const { filename, file_content, file_diff } = inputs.clone();
  const ins = inputs.clone();
  ins.filename = filename;

  if (file_content.length > 0) {
    ins.file_content = file_content;
  }
  if (file_diff.length > 0) {
    ins.file_diff = file_diff;
    const file_diff_tokens = tokenizer.get_token_count(file_diff);
    if (file_diff_tokens < MAX_TOKENS_FOR_EXTRA_CONTENT) {
      // summarize diff
      const summary = await summarize(file_diff, ins);
      return [`${filename}: ${summary}`, await getFinalResponse(ins)];
    }
  }

  const summary = await summarize(file_content, ins);
  return [`${filename}: ${summary}`, await getFinalResponse(ins)];
};

/**
 * Gets the review comment for the given review ID.
 *
 * @param review_id - The ID of the review.
 * @returns The review comment.
 */
export const getReviewComment = async (review_id: number): Promise<string> => {
  const review_comment = await octokit.rest.pulls.getReview({
    owner: context.repo.owner,
    repo: context.repo.repo,
    pull_number: context.payload.pull_request!.number,
    review_id: review_id,
  });
  return review_comment.data.body;
};

/**
 * Creates a review comment on the current pull request.
 *
 * @param body - The body of the comment.
 * @param path - The path of the file being commented on.
 * @param position - The position in the diff where the comment should be placed.
 * @returns The ID of the created comment.
 */
export const createReviewComment = async (
  body: string,
  path: string,
  position: number,
): Promise<number> => {
  const comment = await octokit.rest.pulls.createReview({
    owner: context.repo.owner,
    repo: context.repo.repo,
    pull_number: context.payload.pull_request!.number,
    body: body,
    event: "COMMENT",
    comments: [
      {
        path: path,
        position: position,
        body: body,
      },
    ],
  });
  return comment.data.id;
};

/**
 * Updates a review comment on the current pull request.
 *
 * @param comment_id - The ID of the comment to update.
 * @param body - The new body of the comment.
 * @returns The updated comment.
 */
export const updateReviewComment = async (
  comment_id: number,
  body: string,
): Promise<string> => {
  const comment = await octokit.rest.pulls.updateReviewComment({
    owner: context.repo.owner,
    repo: context.repo.repo,
    pull_number: context.payload.pull_request!.number,
    comment_id: comment_id,
    body: body,
  });
  return comment.data.body;
};

/**
 * Deletes a review comment on the current pull request.
 *
 * @param comment_id - The ID of the comment to delete.
 */
export const deleteReviewComment = async (comment_id: number): Promise<void> => {
  await octokit.rest.pulls.deleteReviewComment({
    owner: context.repo.owner,
    repo: context.repo.repo,
    pull_number: context.payload.pull_request!.number,
    comment_id: comment_id,
  });
};

Let me know if you need anything else.

@harjotgill harjotgill added this pull request to the merge queue Mar 19, 2023
@harjotgill harjotgill merged commit 50b4b93 into main Mar 19, 2023
@harjotgill harjotgill deleted the replies branch March 19, 2023 20:38
shoyuf pushed a commit to maybeLab/openai-mr-reviewer-gltlab that referenced this pull request Jun 25, 2023
…bbitai#64)

<!-- This is an auto-generated comment: release notes by openai -->
### Summary by OpenAI

New Feature: Users can now view file diffs when replying to whole file
review comments. The default system message has been updated and prompts
for confirmation have been added. Additionally, the code now checks for
file_content length before setting it, and updates the Tips section.
<!-- end of auto-generated comment: release notes by openai -->
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant