code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Review Skill

代码审查Skill

You are handling a PR code review interaction. This skill helps you read, understand, and respond to code review feedback.
你正在处理PR代码审查交互。该Skill可帮助你读取、理解并回应代码审查反馈。

When This Skill Applies

该Skill的适用场景

  • Triggered by
    pull_request_review
    or
    pull_request_review_comment
    events
  • User asks you to address review feedback
  • User requests a code review of their changes
  • pull_request_review
    pull_request_review_comment
    事件触发
  • 用户要求你处理审查反馈
  • 用户请求对其代码变更进行审查

Reading Review Comments

读取审查评论

Get All Reviews on a PR

获取PR的所有审查记录

bash
undefined
bash
undefined

List all reviews (approved, changes requested, commented)

List all reviews (approved, changes requested, commented)

gh api repos/$GITHUB_REPOSITORY/pulls/<number>/reviews
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/reviews

Get a specific review's comments

Get a specific review's comments

gh api repos/$GITHUB_REPOSITORY/pulls/<number>/reviews/<review_id>/comments
undefined
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/reviews/<review_id>/comments
undefined

Get Review Comments (Line-Level Feedback)

获取行级审查评论(反馈)

bash
undefined
bash
undefined

All line-level review comments on the PR

All line-level review comments on the PR

gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments

Filter by specific path

Filter by specific path

gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments | jq '.[] | select(.path == "src/example.ts")'
undefined
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments | jq '.[] | select(.path == "src/example.ts")'
undefined

Understanding Review Comment Structure

理解审查评论的结构

Key fields in review comments:
  • path
    : File being commented on
  • line
    /
    original_line
    : Line number in the diff
  • body
    : The reviewer's comment text
  • diff_hunk
    : Code context around the comment
  • in_reply_to_id
    : If this is a reply to another comment
审查评论中的关键字段:
  • path
    : 被评论的文件
  • line
    /
    original_line
    : 差异中的行号
  • body
    : 审查者的评论内容
  • diff_hunk
    : 评论周围的代码上下文
  • in_reply_to_id
    : 若该评论是对另一评论的回复

Responding to Review Feedback

回应审查反馈

Workflow for Addressing Feedback

处理反馈的工作流程

  1. Read the review comments to understand what changes are requested
  2. Read the relevant files using the paths from the comments
  3. Make the requested changes using Edit tool
  4. Commit and push to update the PR
  5. Update your tracking comment to summarize what was addressed
  1. 读取审查评论,明确需要进行哪些变更
  2. 读取相关文件,使用评论中提供的路径
  3. 进行要求的变更,使用编辑工具
  4. 提交并推送以更新PR
  5. 更新你的跟踪评论,总结已处理的内容

Replying to Review Comments

回复审查评论

bash
undefined
bash
undefined

Reply to a specific review comment

Reply to a specific review comment

gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments
-X POST
-f body="Fixed in the latest commit"
-f in_reply_to=<comment_id>
undefined
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments
-X POST
-f body="Fixed in the latest commit"
-f in_reply_to=<comment_id>
undefined

Marking Conversations as Resolved

将对话标记为已解决

After addressing feedback, the reviewer typically resolves the conversation. You can indicate you've addressed it by:
  1. Replying to the comment explaining what you changed
  2. Updating your tracking comment with a summary
处理完反馈后,通常由审查者标记对话为已解决。你可以通过以下方式表明已处理反馈:
  1. 回复评论,说明你进行了哪些变更
  2. 更新你的跟踪评论,总结处理内容

Providing Code Review Feedback

提供代码审查反馈

When asked to review code changes:
当被要求审查代码变更时:

Quick Review Checklist

快速审查清单

  • Correctness: Does the code do what it's supposed to?
  • Security: Are there any security vulnerabilities?
  • Performance: Are there obvious performance issues?
  • Readability: Is the code clear and maintainable?
  • Tests: Are changes tested appropriately?
  • 正确性:代码是否实现了预期功能?
  • 安全性:是否存在安全漏洞?
  • 性能:是否存在明显的性能问题?
  • 可读性:代码是否清晰且易于维护?
  • 测试:变更是否经过了恰当的测试?

Viewing PR Changes

查看PR变更

bash
undefined
bash
undefined

View the diff

View the diff

gh pr diff <number> --repo $GITHUB_REPOSITORY
gh pr diff <number> --repo $GITHUB_REPOSITORY

View changed files list

View changed files list

gh pr view <number> --repo $GITHUB_REPOSITORY --json files
gh pr view <number> --repo $GITHUB_REPOSITORY --json files

Compare with base branch (use two dots for shallow clones in GitHub Actions)

Compare with base branch (use two dots for shallow clones in GitHub Actions)

git diff origin/$BASE_BRANCH..HEAD
undefined
git diff origin/$BASE_BRANCH..HEAD
undefined

Providing Feedback

提供反馈

Post your review feedback to your tracking comment. Structure it clearly:
  • Group feedback by file
  • Reference specific line numbers
  • Distinguish between required changes and suggestions
  • Be constructive and specific
将你的审查反馈发布到跟踪评论中。确保结构清晰:
  • 按文件分组反馈
  • 引用具体行号
  • 区分必填变更和建议
  • 保持反馈具有建设性且具体

Submitting Interactive Reviews

提交交互式审查

Use
gh pr review
to submit formal GitHub reviews that appear in the PR's review UI.
使用
gh pr review
提交正式的GitHub审查,这些审查会显示在PR的审查UI中。

Approve a PR

批准PR

bash
gh pr review <number> --approve --body "LGTM! Changes look good."
bash
gh pr review <number> --approve --body "LGTM! Changes look good."

Request Changes

请求变更

bash
gh pr review <number> --request-changes --body "Please address the following issues..."
bash
gh pr review <number> --request-changes --body "Please address the following issues..."

Leave a Comment Review (without approval/rejection)

留下评论式审查(不批准/拒绝)

bash
gh pr review <number> --comment --body "Some observations about the code..."
bash
gh pr review <number> --comment --body "Some observations about the code..."

Adding Line-Level Comments

添加行级评论

To add comments on specific lines of code (shown inline in GitHub's diff view):
要在代码的特定行添加评论(会显示在GitHub差异视图的内联位置):

Create a Review with Line Comments

创建包含行级评论的审查

bash
undefined
bash
undefined

First, get the latest commit SHA

First, get the latest commit SHA

COMMIT_SHA=$(gh pr view <number> --json headRefOid --jq '.headRefOid')
COMMIT_SHA=$(gh pr view <number> --json headRefOid --jq '.headRefOid')

Create a review comment on a specific position in the diff

Create a review comment on a specific position in the diff

Note: position is the line number in the diff (not the file), starting from 1

Note: position is the line number in the diff (not the file), starting from 1

gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments
-X POST
-f body="Consider using a more descriptive variable name here"
-f commit_id="$COMMIT_SHA"
-f path="src/example.ts"
-F position=10
undefined
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments
-X POST
-f body="Consider using a more descriptive variable name here"
-f commit_id="$COMMIT_SHA"
-f path="src/example.ts"
-F position=10
undefined

Key Fields for Line Comments

行级评论的关键字段

  • commit_id
    : The SHA of the commit to comment on (use latest)
  • path
    : File path relative to repo root
  • position
    : Position in the diff (line number in the diff hunk, starting at 1)
  • body
    : Your comment text
Note: The
position
is the line number within the diff, not the line number in the file. Count lines from the start of the diff hunk.
  • commit_id
    : 要评论的提交SHA(使用最新的)
  • path
    : 相对于仓库根目录的文件路径
  • position
    : 差异中的位置(差异块中的行号,从1开始)
  • body
    : 你的评论内容
注意
position
是差异中的行号,而非文件中的行号。从差异块的开头开始计数行号。

Iterating on Changes

迭代变更

When you need to make additional changes after initial feedback:
bash
undefined
当初次反馈后需要进行额外变更时:
bash
undefined

Ensure you're on the PR branch

Ensure you're on the PR branch

gh pr checkout <number>
gh pr checkout <number>

Make changes, then commit

Make changes, then commit

git add <files> git commit -m "fix: address review feedback"
git add <files> git commit -m "fix: address review feedback"

Push to update the PR

Push to update the PR

git push origin HEAD
undefined
git push origin HEAD
undefined

Important Notes

重要注意事项

  1. Read before responding - Always read the full review context before making changes
  2. Address all comments - Don't leave feedback unaddressed
  3. Communicate clearly - Update your tracking comment to show what you've addressed
  4. Test your changes - Run tests after making review-requested changes
  1. 先阅读再回应 - 进行变更前,务必阅读完整的审查上下文
  2. 处理所有评论 - 不要遗漏任何反馈
  3. 清晰沟通 - 更新你的跟踪评论,展示已处理的内容
  4. 测试变更 - 完成审查要求的变更后,运行测试