code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode 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 or
pull_request_revieweventspull_request_review_comment - 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
undefinedbash
undefinedList 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
undefinedgh api repos/$GITHUB_REPOSITORY/pulls/<number>/reviews/<review_id>/comments
undefinedGet Review Comments (Line-Level Feedback)
获取行级审查评论(反馈)
bash
undefinedbash
undefinedAll 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")'
undefinedgh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments | jq '.[] | select(.path == "src/example.ts")'
undefinedUnderstanding Review Comment Structure
理解审查评论的结构
Key fields in review comments:
- : File being commented on
path - /
line: Line number in the difforiginal_line - : The reviewer's comment text
body - : Code context around the comment
diff_hunk - : If this is a reply to another comment
in_reply_to_id
审查评论中的关键字段:
- : 被评论的文件
path - /
line: 差异中的行号original_line - : 审查者的评论内容
body - : 评论周围的代码上下文
diff_hunk - : 若该评论是对另一评论的回复
in_reply_to_id
Responding to Review Feedback
回应审查反馈
Workflow for Addressing Feedback
处理反馈的工作流程
- Read the review comments to understand what changes are requested
- Read the relevant files using the paths from the comments
- Make the requested changes using Edit tool
- Commit and push to update the PR
- Update your tracking comment to summarize what was addressed
- 读取审查评论,明确需要进行哪些变更
- 读取相关文件,使用评论中提供的路径
- 进行要求的变更,使用编辑工具
- 提交并推送以更新PR
- 更新你的跟踪评论,总结已处理的内容
Replying to Review Comments
回复审查评论
bash
undefinedbash
undefinedReply 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>
-X POST
-f body="Fixed in the latest commit"
-f in_reply_to=<comment_id>
undefinedgh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments
-X POST
-f body="Fixed in the latest commit"
-f in_reply_to=<comment_id>
-X POST
-f body="Fixed in the latest commit"
-f in_reply_to=<comment_id>
undefinedMarking Conversations as Resolved
将对话标记为已解决
After addressing feedback, the reviewer typically resolves the conversation. You can indicate you've addressed it by:
- Replying to the comment explaining what you changed
- Updating your tracking comment with a summary
处理完反馈后,通常由审查者标记对话为已解决。你可以通过以下方式表明已处理反馈:
- 回复评论,说明你进行了哪些变更
- 更新你的跟踪评论,总结处理内容
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
undefinedbash
undefinedView 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
undefinedgit diff origin/$BASE_BRANCH..HEAD
undefinedProviding 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 to submit formal GitHub reviews that appear in the PR's review UI.
gh pr review使用提交正式的GitHub审查,这些审查会显示在PR的审查UI中。
gh pr reviewApprove 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
undefinedbash
undefinedFirst, 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
-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
undefinedgh 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
-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
undefinedKey Fields for Line Comments
行级评论的关键字段
- : The SHA of the commit to comment on (use latest)
commit_id - : File path relative to repo root
path - : Position in the diff (line number in the diff hunk, starting at 1)
position - : Your comment text
body
Note: The is the line number within the diff, not the line number in the file. Count lines from the start of the diff hunk.
position- : 要评论的提交SHA(使用最新的)
commit_id - : 相对于仓库根目录的文件路径
path - : 差异中的位置(差异块中的行号,从1开始)
position - : 你的评论内容
body
注意:是差异中的行号,而非文件中的行号。从差异块的开头开始计数行号。
positionIterating on Changes
迭代变更
When you need to make additional changes after initial feedback:
bash
undefined当初次反馈后需要进行额外变更时:
bash
undefinedEnsure 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
undefinedgit push origin HEAD
undefinedImportant Notes
重要注意事项
- Read before responding - Always read the full review context before making changes
- Address all comments - Don't leave feedback unaddressed
- Communicate clearly - Update your tracking comment to show what you've addressed
- Test your changes - Run tests after making review-requested changes
- 先阅读再回应 - 进行变更前,务必阅读完整的审查上下文
- 处理所有评论 - 不要遗漏任何反馈
- 清晰沟通 - 更新你的跟踪评论,展示已处理的内容
- 测试变更 - 完成审查要求的变更后,运行测试