GitHub Issue 分析
GitHub Issue 分析方法论
为什么需要 Issue 分析?
一个模糊的 Issue 直接开始编码,往往会导致返工。通过系统化的分析,可以在动手前就明确所有细节。
Template Sections
将 Issue 分析为以下 10 个部分:
1. Issue Summary
对 Issue 的简要概述:
## Issue Summary
Add OAuth2 login support for Google accounts to allow users
to sign in without creating a new password.
2. Problem Statement
清晰定义需要解决的问题:
## Problem Statement
Currently, users must create an account with email/password
to access the platform. This creates friction in the onboarding
process and reduces conversion rates.
3. Technical Approach
高层次的解决方案和架构决策:
## Technical Approach
- Use Passport.js with Google OAuth2 strategy
- Store OAuth tokens in existing User model
- Create new AuthProvider enum for multi-provider support
- Implement JWT token refresh for session management
4. Implementation Plan
分步骤的实现任务:
## Implementation Plan
1. Add Google OAuth credentials to environment config
2. Create OAuth callback route and controller
3. Extend User model with provider fields
4. Implement token storage and refresh logic
5. Add "Sign in with Google" button to login page
6. Handle account linking for existing users
5. Test Plan
测试策略和测试用例:
## Test Plan
- Unit tests for OAuth token validation
- Integration tests for callback handling
- E2E tests for complete login flow
- Edge case: existing email, new OAuth provider
- Error handling: expired tokens, revoked access
6. Files to Modify
需要修改的现有文件列表:
## Files to Modify
- src/auth/auth.module.ts - Add OAuth strategy
- src/auth/auth.controller.ts - Add OAuth routes
- src/user/user.schema.ts - Add provider fields
- src/config/auth.config.ts - Add OAuth config
- frontend/pages/login.tsx - Add OAuth button
7. Files to Create
需要创建的新文件:
## Files to Create
- src/auth/strategies/google.strategy.ts
- src/auth/dto/oauth-callback.dto.ts
- src/auth/guards/oauth.guard.ts
- tests/auth/oauth.e2e-spec.ts
8. Existing Utilities to Leverage
可以复用的项目工具/帮助函数:
## Existing Utilities to Leverage
- src/common/guards/jwt.guard.ts - Base guard pattern
- src/common/decorators/user.decorator.ts - User extraction
- src/config/config.service.ts - Environment config access
9. Success Criteria
可衡量的完成标准:
## Success Criteria
- [ ] User can click "Sign in with Google" button
- [ ] OAuth flow redirects and returns correctly
- [ ] User profile is created/updated from Google data
- [ ] JWT token is issued after successful OAuth
- [ ] Existing users can link Google account
- [ ] All tests pass
- [ ] No security vulnerabilities introduced
10. Out of Scope
明确不在此次实现范围内的内容:
## Out of Scope
- Apple Sign In (future issue)
- Facebook Login (future issue)
- Account unlinking
- Multiple Google accounts per user
Process
执行 Issue 分析的流程:
-
Fetch issue details using
gh issue view <issue_number>- 获取 Issue 的完整内容
-
Review related code and project structure
- 理解相关代码和项目结构
-
Analyze requirements thoroughly
- 深入分析需求
-
Create detailed technical specification
- 创建详细的技术规格
-
Follow strict TDD principles, KISS approach
- 遵循 TDD 原则,保持简单
-
Enforce 300-line file limit where applicable
- 文件不超过 300 行
-
Output the full technical specification for review
- 输出完整规格供审查
完整模板
# Technical Specification: [Issue Title]
Issue: #[number]
Author: [name]
Date: [date]
## 1. Issue Summary
[Brief overview]
## 2. Problem Statement
[Clear definition of what needs to be solved]
## 3. Technical Approach
[High-level solution and architecture decisions]
## 4. Implementation Plan
1. [Step 1]
2. [Step 2]
3. [Step 3]
...
## 5. Test Plan
- [Test case 1]
- [Test case 2]
...
## 6. Files to Modify
- [file1.ts] - [reason]
- [file2.ts] - [reason]
## 7. Files to Create
- [newfile1.ts] - [purpose]
- [newfile2.ts] - [purpose]
## 8. Existing Utilities to Leverage
- [utility1] - [usage]
- [utility2] - [usage]
## 9. Success Criteria
- [ ] [Criterion 1]
- [ ] [Criterion 2]
- [ ] [Criterion 3]
## 10. Out of Scope
- [Item 1]
- [Item 2]
---
Ready for Implementation: Yes/No
Blockers: [if any]
让 AI 帮助分析
可以让 AI 帮助分析 GitHub Issue:
请分析这个 GitHub Issue,生成技术实现规格:
[粘贴 Issue 内容]
请包括:
1. 问题陈述
2. 技术方案
3. 实现步骤
4. 测试计划
5. 文件变更清单
6. 成功标准
总结
通过系统化的 Issue 分析:
- 减少开发中的返工
- 明确实现范围和边界
- 提供清晰的验收标准
- 便于团队审查和协作
这是将模糊需求转化为可执行代码的关键步骤。
📚 相关资源
❓ 常见问题
关于本章主题最常被搜索的问题,点击展开答案
为什么不直接看 issue 就开始写代码?
模糊 issue 直接动手通常返工:边界没划清、依赖没列、edge case 没想到,写到一半才发现要改架构。本章方法论把 issue 拆成 10 节技术规格(问题陈述 / 技术方案 / 实现步骤 / 测试计划 / 文件变更 / 复用 utility / 验收标准 / 范围外),动手前 30 分钟整理,省后面几天返工。
技术规格的 10 节具体是哪 10 节?
(1) Issue Summary;(2) Problem Statement;(3) Technical Approach;(4) Implementation Plan(分步任务);(5) Test Plan(含 edge case);(6) Files to Modify(带原因);(7) Files to Create(带用途);(8) Existing Utilities to Leverage(避免重复造轮子);(9) Success Criteria(可勾 checkbox);(10) Out of Scope。最后加一行 Ready for Implementation: Yes/No + Blockers。
Out of Scope 这一节真的有必要写吗?
必要。本章 OAuth 例子 Out of Scope 写明:Apple Sign In / Facebook Login / Account unlinking / 多 Google 账号 — 都是审查者会自然问"为什么不顺手做"的延伸功能。显式列出来防止 scope creep(PR 越写越大)+ 让审查者一眼知道边界,比口头说省 3 轮反复。
Existing Utilities to Leverage 这节为什么单独列?
强制开发者动手前先扫一遍现有代码,避免重复造轮子。本章 OAuth 例子列出 src/common/guards/jwt.guard.ts(base guard 模式)/ src/common/decorators/user.decorator.ts(提取 user)/ src/config/config.service.ts(环境配置)。新写一个 guard 比复用现有的多 200 行代码 + 多一处维护点,列清楚省的就是这些。
用 gh issue view 拉 issue 之后怎么衔接到 spec?
本章 6 步:(1) gh issue view <num> 拉详情;(2) 走读相关代码和项目结构;(3) 深入分析需求;(4) 创建详细技术规格;(5) 严守 TDD + KISS;(6) 文件不超过 300 行;(7) 输出完整规格供审查。第 1-3 步占 60% 时间 — 没读懂上下文写出来的 spec 就是 AI 自己幻觉的需求,必须基于 issue 实际内容。