pr-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePR Review 代码审查技能
PR Code Review Skill
全面审查 Pull Request 的代码质量、安全性、性能和架构设计,提供专业的改进建议
Conduct comprehensive reviews of Pull Request code quality, security, performance, and architectural design, and provide professional improvement suggestions
快速开始
Quick Start
bash
undefinedbash
undefined审查当前分支的 PR
Review the PR of the current branch
gh pr view
gh pr view
审查指定 PR
Review a specified PR
gh pr view 6324
gh pr view 6324
查看变更内容
View changes
gh pr diff 6324
undefinedgh pr diff 6324
undefined工具集成
Tool Integration
使用 gh CLI 加速审查
Accelerate Reviews with gh CLI
bash
undefinedbash
undefined查看并审查 PR
View and review PR
gh pr view <number> && gh pr diff <number>
gh pr view <number> && gh pr diff <number>
添加审查评论
Add review comments
gh pr review <number> --comment -b "我的审查意见"
gh pr review <number> --comment -b "My review comments"
批准 PR
Approve PR
gh pr review <number> --approve
gh pr review <number> --approve
请求修改
Request changes
gh pr review <number> --request-changes
undefinedgh pr review <number> --request-changes
undefined本地测试 PR
Local PR Testing
bash
undefinedbash
undefined检出 PR 分支到本地
Check out PR branch locally
gh pr checkout <number>
gh pr checkout <number>
运行测试
Run tests
pnpm test
pnpm test
运行 lint
Run lint
pnpm lint
pnpm lint
类型检查
Type check
pnpm tsc --noEmit
pnpm tsc --noEmit
启动开发服务器验证
Start dev server to verify
pnpm dev
undefinedpnpm dev
undefined常见命令参考
Common Command Reference
bash
undefinedbash
undefinedPR 信息查看
View PR information
gh pr view --json title,body,author,state,files,additions,deletions
gh pr view --json title,body,author,state,files,additions,deletions
PR diff 查看
View PR diff
gh pr diff
gh pr diff <number> > /tmp/pr.diff # 保存到文件
gh pr diff
gh pr diff <number> > /tmp/pr.diff # Save to file
PR commits 查看
View PR commits
gh pr view --json commits --jq '.commits[].messageHeadline'
gh pr view --json commits --jq '.commits[].messageHeadline'
PR checks 状态
Check PR checks status
gh pr checks
gh pr checks
PR 评论
Comment on PR
gh pr comment <number> --body "评论内容"
gh pr comment <number> --body "Comment content"
PR 审查提交
Submit PR review
gh pr review <number> --approve
gh pr review <number> --request-changes
gh pr review <number> --comment -b "评论内容"
gh pr review <number> --approve
gh pr review <number> --request-changes
gh pr review <number> --comment -b "Comment content"
PR 操作
PR operations
gh pr merge <number> --squash # Squash merge
gh pr close <number> # 关闭 PR
undefinedgh pr merge <number> --squash # Squash merge
gh pr close <number> # Close PR
undefined审查流程
Review Process
1. 信息收集阶段
1. Information Collection Phase
自动执行以下步骤:
bash
undefinedAutomatically execute the following steps:
bash
undefined1. 获取 PR 基本信息
1. Get basic PR information
gh pr view --json title,body,author,state,headRefName,baseRefName,additions,deletions,files
gh pr view --json title,body,author,state,headRefName,baseRefName,additions,deletions,files
2. 获取 PR 变更 diff
2. Get PR change diff
gh pr diff
gh pr diff
3. 获取 PR 的 commit 历史
3. Get PR commit history
gh pr view --json commits
gh pr view --json commits
4. 检查 CI/CD 状态
4. Check CI/CD status
gh pr checks
undefinedgh pr checks
undefined2. 多维度代码审查
2. Multi-Dimensional Code Review
按照以下三个维度进行系统性审查:
Conduct systematic reviews according to the following three dimensions:
维度 1: 代码质量标准 📐
Dimension 1: Code Quality Standards 📐
通用的代码质量标准,适用于所有项目:
- 安全性: 输入验证、权限检查、注入防护、敏感信息保护
- 正确性: 错误处理、边界条件、类型安全
- 性能: 算法复杂度、数据库优化、内存管理
- 可测试性: 测试覆盖、测试质量、Mock 使用
📖 详细指南: code-quality-standards.md
Universal code quality standards applicable to all projects:
- Security: Input validation, permission checks, injection protection, sensitive information protection
- Correctness: Error handling, boundary conditions, type safety
- Performance: Algorithm complexity, database optimization, memory management
- Testability: Test coverage, test quality, Mock usage
📖 Detailed Guide: code-quality-standards.md
维度 2: FastGPT 风格规范 🎨
Dimension 2: FastGPT Style Guide 🎨
FastGPT 项目特定的代码规范和约定:
- 工作流节点开发: 类型定义、节点枚举、执行逻辑、isEntry 管理
- API 路由开发: 路由定义、权限验证、错误处理
- 前端组件开发: TypeScript + React、Chakra UI、状态管理
- 数据库操作: Model 定义、查询优化、索引设计
- 包结构与依赖: 依赖方向、导入规范、类型导出
📖 详细指南: fastgpt-style-guide.md
Project-specific code specifications and conventions for FastGPT:
- Workflow Node Development: Type definitions, node enumerations, execution logic, isEntry management
- API Route Development: Route definitions, permission verification, error handling
- Frontend Component Development: TypeScript + React, Chakra UI, state management
- Database Operations: Model definitions, query optimization, index design
- Package Structure & Dependencies: Dependency direction, import specifications, type exports
📖 Detailed Guide: fastgpt-style-guide.md
维度 3: 常见问题检查清单 🔍
Dimension 3: Common Issues Checklist 🔍
快速识别和修复常见问题模式:
- TypeScript 问题: any 类型滥用、类型定义不完整、不安全断言
- 异步错误处理: 未处理 Promise、错误信息丢失、静默失败
- React 性能: 不必要的重渲染、渲染中创建对象、缺少 memoization
- 工作流节点: isEntry 未重置、交互历史未清理、白名单遗漏
- 安全漏洞: 注入攻击、XSS、文件上传漏洞
📖 详细清单: common-issues-checklist.md
Quickly identify and fix common problem patterns:
- TypeScript Issues: Overuse of any type, incomplete type definitions, unsafe assertions
- Asynchronous Error Handling: Unhandled Promises, lost error messages, silent failures
- React Performance: Unnecessary re-renders, object creation during rendering, missing memoization
- Workflow Nodes: Unreset isEntry, uncleared interaction history, missing whitelist entries
- Security Vulnerabilities: Injection attacks, XSS, file upload vulnerabilities
📖 Detailed Checklist: common-issues-checklist.md
3. 生成并提交审查报告
3. Generate and Submit Review Report
PR 审查输出分为两个部分:
- 整体审查报告: 提交为 PR 顶部的总体评论
- 行级代码评论: 直接在代码行的位置添加具体评论
PR review outputs are divided into two parts:
- Overall Review Report: Submitted as a general comment at the top of the PR
- Line-Level Code Comments: Added directly at the corresponding code lines
步骤 1: 分析代码并准备评论
Step 1: Analyze Code and Prepare Comments
在审查过程中,需要为每个问题记录:
- 文件路径: 如
packages/service/core/workflow/dispatch.ts - 行号: 如
L142-L150 - 问题类型: 🔴严重 / 🟡改进 / 🟢优化
- 评论内容: 具体的问题描述和建议
During the review process, record the following for each issue:
- File Path: e.g.,
packages/service/core/workflow/dispatch.ts - Line Numbers: e.g.,
L142-L150 - Issue Type: 🔴Critical / 🟡Improvement / 🟢Optimization
- Comment Content: Specific issue description and suggestions
步骤 2: 添加行级代码评论
Step 2: Add Line-Level Code Comments
GitHub CLI 支持在特定行添加评论。评论数据格式为 JSON:
bash
undefinedGitHub CLI supports adding comments to specific lines. The comment data format is JSON:
bash
undefined1. 准备行级评论 JSON 文件
1. Prepare line-level comment JSON file
cat > /tmp/line-comments.json << 'EOF'
{
"body": "行级代码审查评论",
"event": "COMMENT",
"comments": [
{
"path": "packages/service/core/workflow/dispatch.ts",
"line": 142,
"body": "🔴 严重问题: 这里缺少错误处理,如果 runtimeNode 为 null 会导致运行时错误。\n\n建议:\n"
},
{
"path": "packages/service/core/workflow/dispatch.ts",
"line": 150,
"body": "🟡 性能优化: 建议将此正则表达式编译提取到函数外部,避免每次调用都重新编译。\n\n建议:\n"
}
]
}
EOF
typescript\nif (!runtimeNode) {\n throw new Error(`Runtime node not found: ${nodeId}`);\n}\ntypescript\nconst NODE_ID_PATTERN = /^node_([a-f0-9]+)$/; // 在模块顶部定义\ncat > /tmp/line-comments.json << 'EOF'
{
"body": "Line-level code review comment",
"event": "COMMENT",
"comments": [
{
"path": "packages/service/core/workflow/dispatch.ts",
"line": 142,
"body": "🔴 Critical Issue: Missing error handling here, which will cause runtime errors if runtimeNode is null.\n\nSuggestion:\n"
},
{
"path": "packages/service/core/workflow/dispatch.ts",
"line": 150,
"body": "🟡 Performance Optimization: It is recommended to compile and extract this regular expression outside the function to avoid re-compiling on each call.\n\nSuggestion:\n"
}
]
}
EOF
typescript\nif (!runtimeNode) {\n throw new Error(`Runtime node not found: ${nodeId}`);\n}\ntypescript\nconst NODE_ID_PATTERN = /^node_([a-f0-9]+)$/; // Define at the top of the module\n2. 提交整体审查报告和行级评论
2. Submit overall review report and line-level comments
gh pr review <number> --body-file /tmp/pr-review.md --json > /tmp/review-result.json
undefinedgh pr review <number> --body-file /tmp/pr-review.md --json > /tmp/review-result.json
undefined步骤 3: 生成整体审查报告
Step 3: Generate Overall Review Report
markdown
undefinedmarkdown
undefinedPR Review: {PR Title}
PR Review: {PR Title}
📊 变更概览
📊 Change Overview
- PR 编号: #{number}
- 作者: @author
- 分支: {baseRefName} ← {headRefName}
- 变更统计: +{additions} -{deletions} 行
- 涉及文件: {files.length} 个文件
- PR Number: #{number}
- Author: @author
- Branches: {baseRefName} ← {headRefName}
- Change Statistics: +{additions} -{deletions} lines
- Files Involved: {files.length} files
✅ 优点
✅ Advantages
{列出做得好的地方}
{List the well-done aspects}
⚠️ 问题汇总
⚠️ Issue Summary
🔴 严重问题 ({count} 个,必须修复)
🔴 Critical Issues ({count} items, must fix)
{简要列出每个严重问题,并在下方添加行级评论}
{Briefly list each critical issue, and add line-level comments below}
🟡 建议改进 ({count} 个)
🟡 Suggested Improvements ({count} items)
{简要列出每个建议}
{Briefly list each suggestion}
🟢 可选优化 ({count} 个)
🟢 Optional Optimizations ({count} items)
{简要列出优化建议}
{Briefly list optimization suggestions}
🧪 测试建议
🧪 Testing Suggestions
{建议的测试方法}
{Recommended testing methods}
💬 总体评价
💬 Overall Evaluation
- 代码质量: ⭐⭐⭐⭐☆ (4/5)
- 安全性: ⭐⭐⭐⭐⭐ (5/5)
- 性能: ⭐⭐⭐⭐☆ (4/5)
- 可维护性: ⭐⭐⭐⭐☆ (4/5)
- Code Quality: ⭐⭐⭐⭐☆ (4/5)
- Security: ⭐⭐⭐⭐⭐ (5/5)
- Performance: ⭐⭐⭐⭐☆ (4/5)
- Maintainability: ⭐⭐⭐⭐☆ (4/5)
🚀 审查结论
🚀 Review Conclusion
{建议: 通过/需修改/拒绝}
{Recommendation: Approve/Needs Changes/Reject}
📍 详细代码评论
📍 Detailed Code Comments
已在以下位置添加了具体的行级评论:
{列出所有添加了行级评论的位置}
undefinedSpecific line-level comments have been added at the following locations:
{List all locations where line-level comments were added}
undefined步骤 4: 提交整体审查报告
Step 4: Submit Overall Review Report
通过 GitHub CLI 提交整体审查报告到评论区。
Submit the overall review report to the comment section via GitHub CLI.
审查命令快速参考:
Quick Reference for Review Commands:
| 场景 | 命令 |
|---|---|
| 批准 PR | |
| 请求修改 | |
| 一般评论 | |
| 从文件提交 | |
| 添加普通评论 | |
| 撤销审查 | |
| Scenario | Command |
|---|---|
| Approve PR | |
| Request changes | |
| General comment | |
| Submit from file | |
| Add regular comment | |
| Dismiss review | |
参考文档
Reference Documents
核心审查文档
Core Review Documents
- 维度 1: code-quality-standards.md - 通用代码质量标准
- 维度 2: fastgpt-style-guide.md - FastGPT 项目规范
- 维度 3: common-issues-checklist.md - 常见问题清单
- Dimension 1: code-quality-standards.md - Universal Code Quality Standards
- Dimension 2: fastgpt-style-guide.md - FastGPT Project Specifications
- Dimension 3: common-issues-checklist.md - Common Issues Checklist