mcpField
C
code-review

code-review

github.com/odyssey4me测试与质量1335 次安装今天更新
代码仓库

关于 code-review

code-review 是用于审查 GitHub PR、GitLab MR 和 Gerrit 变更的工作流技能。它会识别托管平台,结合 CI 状态与仓库专属背景进行评审,也可按需发布评审意见。

主要功能

  1. 01识别 GitHub、GitLab 或 Gerrit
  2. 02获取变更详情、CI 状态和差异
  3. 03检查安全性、可维护性与架构
  4. 04保存仓库专属评审背景
  5. 05可发布评审评论

适用场景

  1. 01审查 PR、MR 或 Gerrit 变更
  2. 02评估变更前检查 CI 状态
  3. 03在后续评审中应用仓库约定

安装

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

$npx skills add https://github.com/odyssey4me/agent-skills --skill code-review

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

附带文件references/review-checklist.mdtile.json

详细介绍

代码审查

协调对 GitHub PR、GitLab MR 和 Gerrit 变更的代码审查。根据 Git 远程配置自动检测平台,并针对安全性、可维护性和架构适配性提供重点审查反馈。

这是一个工作流技能——不包含脚本,而是引导 Agent 使用相应的平台技能完成多步骤审查流程。

身份验证

此技能将身份验证委托给底层平台技能:

  • GitHub:需要 gh auth login(参见 github 技能)
  • GitLab:需要 glab auth login(参见 gitlab 技能)
  • Gerrit:需要 git-review 配置(参见 gerrit 技能)

使用 code-review 前,请确保已通过相关平台技能完成身份验证。

命令

review

按编号或 URL 审查变更。

用法:

Review PR #123
Review this MR: https://gitlab.com/org/repo/-/merge_requests/42
Review Gerrit change 456789

Agent 会按照工作流中的步骤执行:从 Git 远程或提供的 URL 检测平台,获取变更元数据、CI 状态和差异,然后提供结构化的审查反馈。也可以选择发布审查评论。

remember

为当前仓库的审查保存补充上下文。此信息会持久保存,并在今后审查同一仓库时纳入考虑。

用法:

Remember that this repo follows the Google Python Style Guide
Remember: authentication changes must be reviewed by the security team
Remember https://internal-docs.example.com/api-conventions as a reference for API design
Remember that the data layer uses the Repository pattern, not Active Record

关键词:消息开头的 remember 一词会触发保存。上下文会根据当前仓库的远程 URL,存储在 ~/.config/agent-skills/code-review.yaml 中。

保存内容:编码标准、架构决策、外部文档链接、团队约定、审查政策,或任何有助于今后审查的上下文。

forget

移除之前为当前仓库保存的上下文。

用法:

Forget the note about the Google Python Style Guide
Forget all saved context for this repo
show context

显示为当前仓库保存的所有上下文。

用法:

Show review context for this repo
check

验证所需的平台技能是否可用且已通过身份验证。

# For GitHub repos
skills/github/scripts/github.py check

# For GitLab repos
skills/gitlab/scripts/gitlab.py check

# For Gerrit repos
skills/gerrit/scripts/gerrit.py check

仓库上下文

每个仓库的上下文会持久保存在 ~/.config/agent-skills/code-review.yaml 中,并以 git remote get-url origin 返回的远程 fetch URL 为键。每次审查开始时都会加载此上下文(参见工作流中的步骤 0)。

# ~/.config/agent-skills/code-review.yaml
repositories:
  "[email protected]:myorg/myrepo.git":
    references:
      - "https://internal-docs.example.com/api-conventions"
      - "https://google.github.io/styleguide/pyguide.html"
    standards:
      - "All API endpoints must validate input with Pydantic models"
      - "Authentication changes require security team review"
    notes:
      - "Data layer uses Repository pattern, not Active Record"
      - "Legacy modules in src/compat/ are exempt from new style rules"
  "https://gitlab.com/myorg/other-repo.git":
    references:
      - "https://docs.example.com/other-repo/architecture"
    standards: []
    notes:
      - "Migrating from REST to GraphQL -- new endpoints should use GraphQL"

用户在审查期间提供仓库外的上下文时,建议使用 remember 命令将其持久保存。

工作流

步骤 0:加载仓库上下文

开始审查前,检查是否存在已保存的上下文:

git remote get-url origin

读取 ~/.config/agent-skills/code-review.yaml 并查找远程 URL。如果存在上下文,则加载并在整个审查过程中留意:

  • references:评估架构决策时参考这些内容
  • standards:主动检查是否符合各项标准
  • notes:将这些内容纳入审查反馈的考量

如果上下文文件不存在或仓库没有条目,则直接继续,不使用额外上下文。

步骤 1:检测平台

根据仓库上下文确定代码托管平台:

# Check git remotes
git remote -v
  • 如果远程 URL 包含 github.com,则使用 github 技能
  • 如果远程 URL 包含 gitlab,则使用 gitlab 技能
  • 如果存在 .gitreview 文件,则使用 gerrit 技能
  • 如果提供了 URL,则根据 URL 主机名检测平台
步骤 2:获取变更元数据和 CI 状态

GitHub:

skills/github/scripts/github.py prs view <number> --repo OWNER/REPO
skills/github/scripts/github.py prs checks <number> --repo OWNER/REPO

GitLab:

skills/gitlab/scripts/gitlab.py mrs view <number> --repo GROUP/REPO
skills/gitlab/scripts/gitlab.py pipelines list --repo GROUP/REPO

Gerrit:

skills/gerrit/scripts/gerrit.py changes view <change-number>
步骤 3:评估 CI/测试状态

开始审查前,检查 CI/测试是否通过:

  • 如果 CI 通过:进行完整审查
  • 如果 CI 失败:注明失败项,跳过测试能够发现的问题,重点关注测试无法发现的问题(安全性、架构、设计)
  • 如果 CI 待处理:注明状态并继续审查
步骤 4:获取差异

GitHub:

gh pr diff <number>

GitLab:

glab mr diff <number>

Gerrit:

git diff HEAD~1
步骤 5:审查更改

按以下优先级重点审查这些方面的反馈。完整清单请参阅 references/review-checklist.md。

  1. 安全问题:注入漏洞、身份验证/授权缺陷、数据泄露、不安全的反序列化、硬编码密钥
  2. 可维护性:过度复杂、命名不佳、缺少关注点分离、影响可读性的代码重复
  3. 良好的编码实践:错误处理缺失、资源泄漏、竞态条件、系统边界处缺少输入验证
  4. 架构契合度:与现有代码库模式的一致性、抽象级别是否恰当、依赖方向

不要标记:

  • 风格/格式问题(交由代码检查工具处理)
  • 对可读性没有明显影响的细微命名偏好
  • 测试覆盖率缺口(交由 CI 覆盖率工具处理)
  • 已被 CI 失败捕获的问题
步骤 6:呈现发现

将发现整理为结构化审查:

## Code Review: PR #<number> - <title>

### Summary
<1-2 sentence summary of the change and overall assessment>

### CI Status
<passing/failing/pending -- note any failures>

### Findings

#### Security
- [ ] <finding with file:line reference>

#### Maintainability
- [ ] <finding with file:line reference>

#### Coding Practices
- [ ] <finding with file:line reference>

#### Architecture
- [ ] <finding with file:line reference>

### Verdict
<APPROVE / REQUEST_CHANGES / COMMENT -- with brief rationale>

如果用户提出要求,请使用平台技能将审查作为评论发布到 PR/MR:

GitHub:

gh pr review <number> --comment --body "<review>"
# Or approve/request changes:
gh pr review <number> --approve --body "<review>"
gh pr review <number> --request-changes --body "<review>"

GitLab:

glab mr note <number> --message "<review>"
# Or approve:
glab mr approve <number>

示例

审查 GitHub PR
Review PR #42

Agent 将运行 git remote -v,检测到 GitHub 后,使用 skills/github/scripts/github.py prs view 42 获取 PR,使用 skills/github/scripts/github.py prs checks 42 检查 CI,通过 gh pr diff 42 获取差异,并提供结构化审查反馈。

按 URL 审查 GitLab MR
Review https://gitlab.com/myorg/myrepo/-/merge_requests/15
审查并发布评论
Review PR #42 and post your findings as a review comment
仅重点审查安全问题
Review PR #42, focus only on security concerns
为后续审查保存上下文
Remember that this repo uses the Twelve-Factor App methodology
Remember https://wiki.example.com/team/coding-standards as a reference
Remember: all database migrations must be backwards-compatible
显示已保存的上下文
Show review context for this repo

模型指南

此技能负责协调多个子技能,并要求对多步骤工作流进行推理。为获得最佳效果,建议使用能力更强的模型。

故障排除

未检测到平台

请确保你在配置了远程仓库的 Git 仓库中运行:

git remote -v
身份验证错误

请确认底层平台技能已通过身份验证:

# GitHub
gh auth status

# GitLab
glab auth status
没有可用差异

请确保 PR/MR 编号正确,且更改确实存在:

# GitHub
skills/github/scripts/github.py prs view <number>

# GitLab
skills/gitlab/scripts/gitlab.py mrs view <number>

评论

支持 Markdown