gitlink-cli/skills/gitlink-code-review/examples/basic-review-workflow.md

287 lines
6.4 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 基础审查工作流示例
本文档展示一个基础的代码审查工作流,适合初次使用 gitlink-code-review 的用户。
## 📋 场景描述
**场景**: 开发者提交了一个 PR需要快速了解代码变更情况。
**目标**:
1. 获取 PR 基本信息
2. 查看变更的文件列表
3. 快速浏览代码变更
## 🔄 工作流程
```
开始
1. 获取 PR 详情
2. 获取变更文件列表
3. 获取 diff 内容
4. 手动浏览代码变更
完成
```
## 🔧 实施步骤
### 步骤 1获取 PR 详情
**命令**:
```bash
gitlink-cli pr +view --id 123 --format json
```
**目的**: 了解 PR 的基本信息,确认 PR 存在且可访问。
**返回结果**:
```json
{
"ok": true,
"data": {
"id": 123,
"project_issues_index": 123,
"title": "Feature: Add user authentication",
"body": "This PR adds user authentication...",
"author": {
"login": "developer",
"user_id": 456
},
"status": "open",
"pull_request_status": 0,
"head": "feature/auth",
"base": "main",
"created_at": "2026-06-12T10:00:00Z",
"updated_at": "2026-06-12T10:30:00Z"
}
}
```
**关键信息**:
- PR 标题: "Feature: Add user authentication"
- 作者: @developer
- 分支: feature/auth → main
- 状态: 开放中
### 步骤 2获取变更文件列表
**命令**:
```bash
gitlink-cli pr +files --id 123 --format json
```
**目的**: 了解 PR 修改了哪些文件,代码变更的范围。
**返回结果**:
```json
{
"ok": true,
"data": {
"files": [
{
"filename": "src/auth/login.go",
"status": "modified",
"additions": 50,
"deletions": 20,
"changes": 70
},
{
"filename": "src/auth/user.go",
"status": "added",
"additions": 80,
"deletions": 0,
"changes": 80
},
{
"filename": "README.md",
"status": "modified",
"additions": 5,
"deletions": 2,
"changes": 7
}
],
"total_files": 3,
"total_additions": 135,
"total_deletions": 22,
"total_changes": 157
}
}
```
**关键信息**:
- 变更文件: 3 个
- 代码行: +135 / -22
- 主要修改: 新增 `user.go`,修改 `login.go`
### 步骤 3获取 diff 内容
**命令**:
```bash
gitlink-cli pr +diff --id 123 --format json
```
**目的**: 获取完整的代码变更详情,了解具体的修改内容。
**返回结果**:
```json
{
"ok": true,
"data": {
"diff": "diff --git a/src/auth/login.go b/src/auth/login.go\nindex 1234567..abcdefg 100644\n--- a/src/auth/login.go\n+++ b/src/auth/login.go\n@@ -1,10 +1,15 @@\n package auth\n\n+func login(username, password string) error {\n+\tdb, _ := sql.Open(\"mysql\", dsn)\n+\tquery := \"SELECT * FROM users WHERE username = '\" + username + \"'\"\n+\t...\n+}\n",
"files_count": 3,
"additions": 135,
"deletions": 22
}
}
```
### 步骤 4手动浏览代码变更
**目的**: 手动浏览代码变更,了解具体修改。
**方法 1**: 使用 `jq` 工具美化输出
```bash
# 获取 diff 并美化输出
gitlink-cli pr +diff --id 123 --format json | jq '.data.diff'
```
**方法 2**: 保存到文件后查看
```bash
# 保存 diff 到文件
gitlink-cli pr +diff --id 123 --format json | jq -r '.data.diff' > pr_diff.txt
# 使用文本编辑器查看
cat pr_diff.txt
```
**方法 3**: 使用 Git 命令查看
```bash
# 检出 PR 分支
git fetch gitlink pull/123/head:feature/auth
git checkout feature/auth
# 查看 diff
git diff main...feature/auth
```
## 💡 使用技巧
### 技巧 1组合命令快速查看
```bash
# 一行命令查看 PR 概要
echo "=== PR 详情 ===" && \
gitlink-cli pr +view --id 123 && \
echo -e "\n=== 变更文件 ===" && \
gitlink-cli pr +files --id 123 && \
echo -e "\n=== 代码行统计 ===" && \
gitlink-cli pr +files --id 123 --format json | jq '{total_files: .data.total_files, total_additions: .data.total_additions, total_deletions: .data.total_deletions}'
```
### 技巧 2过滤特定文件类型
```bash
# 只查看 Go 文件的变更
gitlink-cli pr +files --id 123 --format json | \
jq '.data.files[] | select(.filename | endswith(".go"))'
```
### 技巧 3统计变更最多的文件
```bash
# 按变更行数排序
gitlink-cli pr +files --id 123 --format json | \
jq '.data.files | sort_by(.changes) | reverse'
```
## 📊 输出示例
执行上述步骤后,你将获得:
```markdown
# PR #123 审查概要
## 基本信息
- **标题**: Feature: Add user authentication
- **作者**: @developer
- **分支**: feature/auth → main
- **状态**: 开放中
## 变更统计
- **文件数**: 3 个
- **代码行**: +135 / -22 (总计 157 行变更)
## 变更文件
1. **src/auth/login.go** (修改)
- +50 / -20 行
- 主要变更:添加登录函数
2. **src/auth/user.go** (新增)
- +80 / -0 行
- 主要变更:新增用户管理模块
3. **README.md** (修改)
- +5 / -2 行
- 主要变更:更新文档说明
## 初步观察
- ✅ 新增用户认证功能,符合项目需求
- ⚠️ 需要关注登录函数的安全性
- 文档已同步更新
## 下一步
1. 详细审查代码变更
2. 检查安全问题
3. 验证功能完整性
```
## 🎯 后续行动
完成基础审查后,可以:
1. **进行深度审查**
- 使用 [`comprehensive-review-workflow.md`](comprehensive-review-workflow.md) 进行全面审查
2. **重点关注问题**
- 如果发现安全问题,参考 [`../references/code-review-security.md`](../references/code-review-security.md)
- 如果发现性能问题,参考 [`../references/code-review-performance.md`](../references/code-review-performance.md)
3. **添加审查评论**
- 参考 [`../references/code-review-comment.md`](../references/code-review-comment.md) 添加评论
## ❓ 常见问题
### Q: 如何查看大型 PR 的 diff
**A**: 大型 PR>1000 行)建议:
1. 分批查看,按文件逐个审查
2. 优先查看核心文件
3. 使用 Git 命令分页查看
### Q: 如何保存审查结果?
**A**:
```bash
# 保存完整的审查数据
gitlink-cli pr +view --id 123 --format json > pr_info.json
gitlink-cli pr +files --id 123 --format json > pr_files.json
gitlink-cli pr +diff --id 123 --format json > pr_diff.json
```
## 📚 相关文档
- [全面审查工作流](comprehensive-review-workflow.md) - 深度代码审查
- [自动审查工作流](auto-review-pr.md) - AI 自动审查
- [PR 操作指南](../../gitlink-pr/SKILL.md) - PR 基础操作
---
*最后更新: 2026-06-12*