关于 sc-pr-check
sc-pr-check 是用于创建 PR 前运行本地 CI 检查的技能。它会识别项目工具、执行选定检查,并支持交互式修复和重新运行。
主要功能
- 01自动识别项目工具
- 02运行 lint、格式、测试、类型、安全、构建和 E2E 检查
- 03选择性检查与快速模式
- 04交互式或自动修复
- 05汇总结果并重新运行
适用场景
- 01创建 PR 前进行本地验证
- 02开发时仅运行测试或 lint
- 03通过 dry-run 查看识别出的检查
- 04应用修复后重新运行全部检查
MCP 相关
该技能说明可选用 PAL MCP 调试测试、审查安全问题并进行提交前验证,也可用 Rube MCP 发布结果到 Slack 或更新 Jira。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ tony363/ superclaude --skill sc-pr-check安装后在 Claude Code 中输入/sc-pr-check确认已加载。
详细介绍
PR 前检查技能
在创建 PR 前运行全面的本地 CI 检查。自动检测项目工具,运行所有检查,并在失败时提供交互式修复。
快速开始
# Run all detected checks
/sc:pr-check
# Run specific check categories
/sc:pr-check --only lint,test
# Quick mode - skip slow checks (e2e, security)
/sc:pr-check --quick
# Fix mode - auto-fix what's possible
/sc:pr-check --fix
# Dry run - show what would be checked
/sc:pr-check --dry-run
行为流程
- 检测 - 识别项目工具(语言、检查工具、格式化工具、测试运行器、安全扫描器)
- 计划 - 根据检测到的工具构建检查顺序
- 执行 - 按顺序运行检查,并实时输出
- 修复 - 失败时,按检查类型提供交互式修复
- 重新运行 - 修复后重新运行所有检查,直到全部通过或用户停止
- 报告 - 汇总结果和已应用的修复
标志
| 标志 | 类型 | 默认值 | 描述 |
|---|---|---|---|
--only | string | all | 逗号分隔:lint、format、test、security、types、e2e、build |
--quick | bool | false | 跳过耗时检查(e2e、安全扫描) |
--fix | bool | false | 自动修复可修复的问题,无需提示 |
--dry-run | bool | false | 显示检测到的检查项,但不运行 |
--strict | bool | false | 将警告视为错误 |
阶段 1:项目工具检测
通过检查配置文件和包清单,自动检测项目使用的工具。
检测矩阵
| 检查类型 | Python | JavaScript/TypeScript | Go | Rust |
|---|---|---|---|---|
| 检查工具 | ruff、flake8、pylint | eslint、biome | golangci-lint | clippy |
| 格式化工具 | ruff format、black | prettier、biome | gofmt | rustfmt |
| 类型检查 | mypy、pyright | tsc | (内置) | (内置) |
| 测试 | pytest、unittest | jest、vitest、mocha | go test | cargo test |
| 安全 | bandit、pip-audit | npm audit、snyk | govulncheck | cargo audit |
| 构建 | - | tsc、vite build | go build | cargo build |
| 端到端测试 | - | playwright、cypress | - | - |
检测策略
# Python detection
[ -f "pyproject.toml" ] || [ -f "setup.py" ] || [ -f "requirements.txt" ]
# JavaScript/TypeScript detection
[ -f "package.json" ] || [ -f "tsconfig.json" ]
# Go detection
[ -f "go.mod" ]
# Rust detection
[ -f "Cargo.toml" ]
# Check for specific tools in config files
grep -q "ruff" pyproject.toml 2>/dev/null # Ruff
[ -f ".eslintrc*" ] || grep -q "eslint" package.json 2>/dev/null # ESLint
检测输出
## Project Tooling Detected
| Category | Tool | Config | Status |
|----------|------|--------|--------|
| Language | Python 3.12 | pyproject.toml | OK |
| Linter | Ruff | pyproject.toml [tool.ruff] | OK |
| Formatter | Ruff Format | pyproject.toml [tool.ruff] | OK |
| Type Check | mypy | pyproject.toml [tool.mypy] | OK |
| Tests | pytest | pyproject.toml [tool.pytest] | OK |
| Security | bandit | .bandit | OK |
| E2E | playwright | playwright.config.ts | OK |
Running 7 checks...
阶段 2:检查执行
按依赖顺序运行检查:
| 步骤 | 检查 | 原因 |
|---|---|---|
| 1 | 检查工具 | 首先捕获语法/风格错误(最快) |
| 2 | 格式化工具 | 确保格式一致 |
| 3 | 类型检查器 | 在运行时之前捕获类型错误 |
| 4 | 单元/集成测试 | 验证正确性 |
| 5 | 安全扫描 | 捕获漏洞 |
| 6 | 构建 | 验证编译 |
| 7 | 端到端测试 | 完整集成测试(最慢,使用 --quick 时跳过) |
执行模式
对每项检查:
- 显示步骤编号和检查名称:
[1/7] Running Ruff linter... - 在超时限制内执行命令
- 捕获退出代码和输出
- 成功时:显示绿色勾号,然后继续下一项
- 失败时:进入修复流程
阶段 3:交互式修复
检查失败时,识别失败类型并提供有针对性的修复方案。
检查失败
[1/7] Ruff linter... FAILED (3 errors)
src/api/routes.py:15:1 F401 unused import
src/models/user.py:8:5 E712 comparison to True
src/utils/helpers.py:22:80 E501 line too long
Actions:
[f] Auto-fix with `ruff check . --fix` (fixes 2 of 3)
[m] Manually fix remaining issues
[s] Skip and continue
[q] Quit
测试失败
[4/7] Tests... FAILED (2 failures)
FAILED tests/test_api.py::test_create_user - AssertionError
FAILED tests/test_auth.py::test_login_expired - TimeoutError
Actions:
[a] Analyze and fix failing tests
[r] Re-run failed tests only
[s] Skip and continue
[q] Quit
安全失败
[5/7] Security scan... FOUND 2 issues
HIGH: SQL injection risk in src/api/users.py:45 (B608)
LOW: Assert used in production code src/utils/debug.py:12 (B101)
Actions:
[a] Analyze and remediate issues
[i] Show details for each finding
[s] Skip and continue
[q] Quit
修复类型参考
| 检查 | 可自动修复 | 需要手动修复 |
|---|---|---|
| 检查 | 大多数风格问题 | 逻辑错误、未使用代码的处理决策 |
| 格式 | 所有格式问题 | 无 |
| 类型 | 无 | 类型注解、类型转换 |
| 测试 | 部分断言修复 | 逻辑错误、模拟对象更新 |
| 安全 | 部分模式 | 架构更改 |
| 构建 | 依赖项安装 | 代码错误 |
| 端到端测试 | 选择器更新 | 流程更改 |
阶段 4:修复后重新运行
应用任何修复后:
- 重新运行所有检查(而不仅仅是失败项)
- 持续修复,直到全部通过或用户退出
- 跟踪会话期间应用的所有修复
阶段 5:结果报告
## PR Check Results
**Status**: ALL PASSED | X FAILED
**Duration**: Ns
### Check Results
| Step | Check | Status | Duration |
|------|-------|--------|----------|
| 1/7 | Ruff linter | PASSED | 1.2s |
| 2/7 | Ruff formatter | PASSED | 0.8s |
| 3/7 | Type check | PASSED | 3.4s |
| 4/7 | Tests (48 passed) | PASSED | 12.1s |
| 5/7 | Security scan | PASSED | 2.3s |
| 6/7 | Build | PASSED | 5.6s |
| 7/7 | E2E tests | SKIPPED | --quick |
### Fixes Applied (if any)
- Auto-fixed 3 lint errors (ruff --fix)
- Fixed test assertion in test_create_user
- Remediated B608 SQL injection in users.py
### Next Steps
- Run `/sc:git commit` to commit changes
- Run `/sc:readme` to update documentation
- Create PR with `gh pr create`
MCP 集成
PAL MCP
| 工具 | 使用时机 | 用途 |
|---|---|---|
mcp__pal__debug | 测试失败 | 分析失败测试的根本原因 |
mcp__pal__codereview | 发现安全问题 | 验证安全修复 |
mcp__pal__precommit | 最终验证 | 多模型提交前检查 |
PAL 使用模式
# Pre-commit validation after all checks pass
mcp__pal__precommit(
path="/path/to/repo",
step="Validating all changes before PR",
findings="Lint, test, security, type check results",
confidence="high"
)
# Debug complex test failure
mcp__pal__debug(
step="Investigating intermittent test failure in test_auth",
hypothesis="Race condition in async test setup",
confidence="medium"
)
Rube MCP
| 工具 | 适用场景 | 用途 |
|---|---|---|
mcp__rube__RUBE_MULTI_EXECUTE_TOOL | 通知 | 将结果发布到 Slack,更新 Jira |
工具协调
- Bash - 执行代码检查工具、格式化工具、测试运行器、安全扫描器
- Glob - 检测配置文件以识别工具
- Grep - 解析失败输出,查找配置模式
- Read - 读取失败的测试文件和安全发现
- Edit - 应用自动修复
相关技能
/sc:test- 详细的测试执行与覆盖率/sc:log-fix- 根据日志分析进行调试/sc:git- Git 工作流操作/sc:analyze- 深入分析代码质量
评论
支持 Markdown