mcpField
C
code-review

code-review

github.com/letta-ai测试与质量1638 次安装3 周前更新
代码仓库

关于 code-review

用于处理 GitHub 拉取请求审查的技能,涵盖理解反馈、修改代码和说明处理结果,也介绍如何查看差异并提交正式或行内审查意见。

主要功能

  1. 01读取 PR 审查与行内评论
  2. 02查看拉取请求差异和文件
  3. 03落实并汇报修改请求
  4. 04提交正式及行内审查意见

适用场景

  1. 01处理 PR 中的修改请求
  2. 02审查分支上的代码变更
  3. 03回复特定审查评论
  4. 04提交批准或修改请求

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/letta-ai/letta-code-action --skill code-review

安装后在 Claude Code 中输入/code-review确认已加载。

详细介绍

代码审查技能

你正在处理 PR 代码审查交互。此技能可帮助你阅读、理解并回应代码审查反馈。

适用场景

  • 由 pull_request_review 或 pull_request_review_comment 事件触发
  • 用户要求你处理审查反馈
  • 用户请求审查其更改

阅读审查评论

获取 PR 的所有审查
# List all reviews (approved, changes requested, commented)
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/reviews

# Get a specific review's comments
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/reviews/<review_id>/comments
获取审查评论(针对具体行的反馈)
# All line-level review comments on the PR
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments

# Filter by specific path
gh api repos/$GITHUB_REPOSITORY/pulls/<number>/comments | jq '.[] | select(.path == "src/example.ts")'
理解审查评论结构

审查评论中的关键字段:

  • path:被评论的文件
  • line / original_line:差异中的行号
  • body:审查者的评论内容
  • diff_hunk:评论附近的代码上下文
  • in_reply_to_id:如果这是对另一条评论的回复

回应审查反馈

处理反馈的工作流
  1. 阅读审查评论,了解需要做出哪些更改
  2. 阅读相关文件,使用评论中的路径定位文件
  3. 使用 Edit 工具进行所要求的更改
  4. 提交并推送,以更新 PR
  5. 更新跟踪评论,总结已处理的内容
回复审查评论
# 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>
将对话标记为已解决

处理完反馈后,审查者通常会将对话标记为已解决。你可以通过以下方式表明已处理:

  1. 回复评论,说明你做了哪些更改
  2. 更新跟踪评论,添加摘要

提供代码审查反馈

当被要求审查代码更改时:

快速审查清单
  • 正确性:代码是否实现了预期功能?
  • 安全性:是否存在安全漏洞?
  • 性能:是否存在明显的性能问题?
  • 可读性:代码是否清晰且易于维护?
  • 测试:是否对更改进行了适当的测试?
查看 PR 更改
# View the diff
gh pr diff <number> --repo $GITHUB_REPOSITORY

# View changed files list
gh pr view <number> --repo $GITHUB_REPOSITORY --json files

# Compare with base branch (use two dots for shallow clones in GitHub Actions)
git diff origin/$BASE_BRANCH..HEAD
提供反馈

将审查反馈发布到你的跟踪评论中。清晰地组织内容:

  • 按文件归纳反馈
  • 注明具体行号
  • 区分必须更改的内容和建议
  • 提供有建设性且具体的意见

提交交互式审查

使用 gh pr review 提交正式的 GitHub 审查,这些审查会显示在 PR 的审查界面中。

批准 PR
gh pr review <number> --approve --body "LGTM! Changes look good."
请求更改
gh pr review <number> --request-changes --body "Please address the following issues..."
留下评论审查(不批准也不拒绝)
gh pr review <number> --comment --body "Some observations about the code..."

添加针对具体行的评论

要对代码的特定行发表评论(评论会内嵌显示在 GitHub 的差异视图中):

创建带行级评论的审查
# First, get the latest commit SHA
COMMIT_SHA=$(gh pr view <number> --json headRefOid --jq '.headRefOid')

# 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
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
行级评论的关键字段
  • commit_id:要评论的提交 SHA(使用最新的提交)
  • path:相对于仓库根目录的文件路径
  • position:差异中的位置(差异块内的行号,从 1 开始)
  • body:你的评论内容

注意:position 是差异中的行号,而不是文件中的行号。从差异块的开头开始计数。

迭代修改

初次收到反馈后,如果需要进行更多更改:

# Ensure you're on the PR branch
gh pr checkout <number>

# Make changes, then commit
git add <files>
git commit -m "fix: address review feedback"

# Push to update the PR
git push origin HEAD

重要说明

  1. 先阅读再回应——更改前务必阅读完整的审查上下文
  2. 处理所有评论——不要遗漏未处理的反馈
  3. 清晰沟通——更新跟踪评论,说明已处理的内容
  4. 测试更改——完成审查要求的更改后运行测试

评论

支持 Markdown