关于 pr-checks
pr-checks 是用于系统处理现有拉取请求审查反馈并运行检查的技能。流程涵盖 PR 信息、CodeRabbit 评论、格式钩子、测试及可选审查工具。
主要功能
- 01检查 PR 状态和说明
- 02经确认后处理 CodeRabbit 反馈
- 03运行 pre-commit 钩子和测试
- 04验证配置并准备修复
- 05生成 PR 检查摘要
适用场景
- 01处理开放 PR 上的反馈
- 02请求最终审查前检查更改
- 03修复审查意见后运行测试和格式检查
- 04汇总 PR 验证结果
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ massgen/ massgen --skill pr-checks安装后在 Claude Code 中输入/pr-checks确认已加载。
详细介绍
PR 检查技能
此技能会运行全面的 PR 检查,以确保代码质量,并处理现有拉取请求中的审查反馈。
使用时机
在以下情况下运行此技能:
- 已创建 PR,且 CodeRabbit 已发布审查评论
- 你想系统地处理现有审查反馈
- 在请求对 PR 进行最终审查或合并之前
用法
/pr-checks
工作流
1. 分析当前状态
首先,了解审查内容:
# Check current branch and status
git branch --show-current
git status --short
# Show diff summary vs main
git diff --stat main...HEAD
# Get the PR number for this branch
gh pr view --json number,title,state
2. 检查并修复 PR 描述
在处理代码评论之前,确保 PR 有合适的描述:
# View current PR description
gh pr view --json body,title
一份好的 PR 描述应包含:
- 摘要:用 1-3 个项目符号说明 PR 的作用
- 测试计划:如何验证更改有效
- 相关问题:Linear/GitHub 问题的链接(例如,
Closes MAS-XXX)
如果描述缺失或不充分:
# Update the PR description
gh pr edit --body "$(cat <<'EOF'
## Summary
<1-2 sentence overview of what this PR accomplishes>
### Changes
- <change 1: what was added/modified/removed>
- <change 2>
- <change 3>
- ...
### Technical details (if applicable)
<Brief explanation of implementation approach, architectural decisions, or non-obvious changes>
## Test plan
- [ ] <verification step 1>
- [ ] <verification step 2>
- [ ] <edge case or error scenario tested>
## Related issues
Closes MAS-XXX
## Screenshots/recordings (if applicable)
<Add screenshots for UI changes, terminal output for CLI changes>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
EOF
)"
必要时修复标题(应遵循 Conventional Commits 格式):
# Update PR title
gh pr edit --title "feat: descriptive title here"
3. 检查现有 CodeRabbit 评论
这是主要工作流。 CodeRabbit 会自动审查 PR 并发布评论。使用 /pr-comments 获取并处理这些评论:
/pr-comments
这会获取 PR 中的所有审查评论。对于每条 CodeRabbit 评论:
- 阅读评论——了解 CodeRabbit 提出的建议
- 评估相关性——这是否是针对此代码库的合理问题?
- 决定采取的操作——以下之一:
- ✅ 实施——建议合理,值得修复
- ❌ 跳过——建议不适用或问题太小
- ❓ 澄清——需要向用户了解更多背景后再决定
与用户逐条讨论评论:
## CodeRabbit Comment #1 of 5
**File:** `massgen/backend/foo.py:45`
**Original code:**
```python
response = client.api_call(params)
return response.data
CodeRabbit 建议:
考虑为 API 调用添加错误处理。请求可能因网络问题 或 API 错误而失败,从而导致未处理的异常。由于此调用 来自主编排循环,失败可能导致整个运行崩溃, 因此这一点尤为重要。 [已截断 - 另有 8 行]
建议的更改:
try:
response = client.api_call(params)
return response.data
except APIError as e:
logger.error(f"API call failed: {e}")
raise
我的评估: 这是合理的问题——API 调用可能失败,而且没有错误处理。
建议: ✅ 实施
你希望我:
- 实施此修复
- 跳过此评论
- 了解更多信息
**After user decides, resolve the comment on GitHub:**
```bash
# If implemented or intentionally skipped, resolve the comment thread
gh api graphql -f query='
mutation {
resolveReviewThread(input: {threadId: "THREAD_ID"}) {
thread { isResolved }
}
}
'
或者,回复评论并说明所采取的操作:
# Reply to the comment
gh pr comment <PR_NUMBER> --body "Addressed in <commit-sha>: <brief description of fix>"
展示评论时:
- 显示正在讨论的原始代码
- 显示完整建议文本(超过 15 行时截断,并附上“[已截断 - 另有 N 行]”)
- 如果 CodeRabbit 提供了建议的更改,也一并显示
- 提供行号作为上下文
在实施每项修复之前,等待用户批准。这样可以确保:
- 用户可以决定要进行哪些更改
- 不会引入不必要的更改
- 可以根据具体上下文作出决定
4. 运行提交前钩子
完成修复后,运行 pre-commit 以确保代码风格符合要求:
uv run pre-commit run --all-files
如果发现问题,请修复并提交。
5. 运行测试
# Run tests (skip expensive API tests)
uv run pytest massgen/tests/ -v -m "not expensive and not docker" -x --tb=short
6. 验证配置(如果有修改)
uv run python scripts/validate_all_configs.py
7. 提交并推送修复
# Stage fixes
git add -u .
# Commit with descriptive message
git commit -m "fix: address CodeRabbit review comments
- Fix error handling in foo.py
- Add missing type hints in bar.py
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>"
# Push to trigger CodeRabbit re-review
git push
8. 运行 PR 审查工具包(可选)
如需进行 CodeRabbit 之外的补充分析:
/pr-review-toolkit:review-pr
这会运行专门的 Agent,以执行以下任务:
- 根据项目指南审查代码
- 检测静默失败
- 分析类型设计
- 分析测试覆盖率
9.(可选)运行本地 CodeRabbit 审查
如果你想进行一次全新的本地审查(与 GitHub PR 评论分开):
coderabbit --prompt-only --type committed
注意: 这会在本地运行 CodeRabbit 自身的分析,结果可能与自动 PR 审查不同。第 3 步中的 GitHub PR 评论通常更全面,因为它们拥有完整的 PR 上下文。
10. 生成摘要
所有检查完成后,输出摘要:
## PR Checks Summary
### Branch: feature/my-feature
- PR #123: "feat: add new feature"
- Commits ahead of main: 3
- Files changed: 5
### PR Description
✅ Has summary, test plan, and issue links
### CodeRabbit Comments Addressed
| Comment | File | Action |
|---------|------|--------|
| Add error handling | foo.py:45 | ✅ Implemented |
| Consider caching | bar.py:12 | ❌ Skipped (not applicable) |
| Missing type hint | baz.py:78 | ✅ Implemented |
### Check Results
| Check | Status |
|-------|--------|
| Pre-commit | ✅ Passed |
| Tests | ✅ 47 passed |
| Config Validation | ✅ Valid |
### Ready for Merge?
✅ All critical issues addressed, ready for final review
参考
PR 描述模板
## Summary
<1-2 sentence overview of what this PR accomplishes>
### Changes
- <change 1: what was added/modified/removed>
- <change 2>
- <change 3>
### Technical details (if applicable)
<Implementation approach, architectural decisions, or non-obvious changes>
## Test plan
- [ ] Step to verify functionality
- [ ] Edge cases tested
- [ ] Error scenarios handled
## Related issues
Closes MAS-XXX
## Screenshots/recordings (if applicable)
<For UI/CLI changes>
## Breaking changes (if applicable)
<What breaks and migration steps>
PR 标题格式
使用 conventional commits 格式:
feat:- 新功能fix:- 修复错误docs:- 仅修改文档refactor:- 不修复错误也不添加功能的代码更改perf:- 性能改进test:- 添加或更新测试chore:- 维护任务
Pre-commit 钩子
- black - Python 格式化工具(行长 200 字符)
- isort - 导入排序工具
- flake8 - 代码风格检查工具
- autoflake - 移除未使用的导入
测试标记
@pytest.mark.expensive- 在快速检查中跳过@pytest.mark.docker- 依赖 Docker
CodeRabbit 配置
请参阅 .coderabbit.yaml,了解针对特定路径的审查说明和排除项。