mcpField
S
sc-pr-check

sc-pr-check

github.com/tony363测试与质量2067 次安装30 周前更新
代码仓库

关于 sc-pr-check

sc-pr-check 是用于创建 PR 前运行本地 CI 检查的技能。它会识别项目工具、执行选定检查,并支持交互式修复和重新运行。

主要功能

  1. 01自动识别项目工具
  2. 02运行 lint、格式、测试、类型、安全、构建和 E2E 检查
  3. 03选择性检查与快速模式
  4. 04交互式或自动修复
  5. 05汇总结果并重新运行

适用场景

  1. 01创建 PR 前进行本地验证
  2. 02开发时仅运行测试或 lint
  3. 03通过 dry-run 查看识别出的检查
  4. 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

行为流程

  1. 检测 - 识别项目工具(语言、检查工具、格式化工具、测试运行器、安全扫描器)
  2. 计划 - 根据检测到的工具构建检查顺序
  3. 执行 - 按顺序运行检查,并实时输出
  4. 修复 - 失败时,按检查类型提供交互式修复
  5. 重新运行 - 修复后重新运行所有检查,直到全部通过或用户停止
  6. 报告 - 汇总结果和已应用的修复

标志

标志类型默认值描述
--onlystringall逗号分隔:lint、format、test、security、types、e2e、build
--quickboolfalse跳过耗时检查(e2e、安全扫描)
--fixboolfalse自动修复可修复的问题,无需提示
--dry-runboolfalse显示检测到的检查项,但不运行
--strictboolfalse将警告视为错误

阶段 1:项目工具检测

通过检查配置文件和包清单,自动检测项目使用的工具。

检测矩阵
检查类型PythonJavaScript/TypeScriptGoRust
检查工具ruff、flake8、pylinteslint、biomegolangci-lintclippy
格式化工具ruff format、blackprettier、biomegofmtrustfmt
类型检查mypy、pyrighttsc(内置)(内置)
测试pytest、unittestjest、vitest、mochago testcargo test
安全bandit、pip-auditnpm audit、snykgovulncheckcargo audit
构建-tsc、vite buildgo buildcargo 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. 显示步骤编号和检查名称:[1/7] Running Ruff linter...
  2. 在超时限制内执行命令
  3. 捕获退出代码和输出
  4. 成功时:显示绿色勾号,然后继续下一项
  5. 失败时:进入修复流程

阶段 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:修复后重新运行

应用任何修复后:

  1. 重新运行所有检查(而不仅仅是失败项)
  2. 持续修复,直到全部通过或用户退出
  3. 跟踪会话期间应用的所有修复

阶段 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