PR Pilot — PR Submission & Lifecycle Management
Overview
Submit professional-quality pull requests and manage them through the full review lifecycle until merge (or closure). Covers PR creation, CI monitoring, review response, iteration, and tracking.
Use cases: Open-source contributions, team code reviews, multi-repo PR management, any code submission workflow.
Prerequisites
GitHub CLI must be authenticated — PR creation, review monitoring, and commenting all require it:
CODEBLOCK0
If not configured, ask the user to provide:
- 1. GitHub username — used for
--head {username}:{branch} and PR search - GitHub token — run
gh auth login or set INLINECODE2
Token is required for: creating PRs, posting comments, checking review status, pushing iterations.
Part 1: Submit the PR
Step 1: Stage & Commit (if not done)
CODEBLOCK1
Step 2: Push to Remote
CODEBLOCK2
Step 3: Write PR Description
Use this structured template. Adapt sections based on PR type and scope.
CODEBLOCK3
{paste test output}
N passed in X.XXs
CODEBLOCK4
Adaptation by PR type
| PR Type | Focus Sections | Skip/Minimize |
|---|
| Bug fix | Problem + Solution + Testing | Design Decisions (unless non-obvious) |
| Feature |
All sections + Extensibility Example | — |
| Security fix | Defense-in-depth, bypass scenarios, residual risk | — |
| Refactor | Motivation, before/after comparison | Problem (reframe as "improvement") |
Step 4: Create the PR
CODEBLOCK5
Step 5: Verify
CODEBLOCK6
PR Description Quality Checklist
- - [ ] Links to the issue being fixed (with
Closes #N) - [ ] Explains root cause, not just symptom
- [ ] Describes solution approach and design decisions
- [ ] Includes test results
- [ ] Has file change summary table
- [ ] Addresses backward compatibility
Part 2: Manage the PR Lifecycle
2a. Monitor PR Status
Check status periodically:
CODEBLOCK7
2b. Respond to Reviews
When a reviewer provides feedback, classify and respond:
Pattern 1: Actionable Code Fix
Reviewer: "This should handle the null case" / "Add error handling for X"
Action: Fix code → add test → push → reply.
CODEBLOCK8
Pattern 2: Architecture Concern
Reviewer: "This approach is fundamentally flawed because..."
Action: If fundamental, consider full rearchitecture.
CODEBLOCK9
Steps for major rework:
- 1. Create new branch from upstream
- Reimplement with new approach
- Create new PR referencing the old
- Close old PR with comment pointing to new one
- Reply to reviewer on new PR
Pattern 3: Style / Convention Nit
Reviewer: "We use camelCase here" / "Please add docstring"
Action: Quick fix → push → reply.
CODEBLOCK10
Pattern 4: Question / Clarification
Reviewer: "Why did you choose X over Y?"
Action: Explain clearly. If they suggest a better approach, adopt it.
CODEBLOCK11
Pattern 5: Request for Tests
Reviewer: "Can you add a test for the edge case where...?"
Action: Write test → verify → push → reply.
CODEBLOCK12
Iteration Workflow
CODEBLOCK13
2c. Handle CI Failures
CODEBLOCK14
| CI Result | Action |
|---|
| Failure in your code | Fix and push |
| Pre-existing/flaky failure |
Comment on PR noting it |
| CI needs config | Check CONTRIBUTING.md |
| Merge conflicts |
git fetch upstream && git rebase upstream/main, resolve, force push |
2d. Track Progress
Maintain {workspace}/pr-tracker.md for multi-PR management:
CODEBLOCK15
Status icons:
- - 🟢 Open — Waiting for review
- 🟡 Changes Requested — Needs iteration
- 🔵 Approved — Ready to merge
- 🟣 Merged
- 🔴 Closed (not merged)
Update the tracker after each PR event (creation, review, iteration, merge, close).
Review Response Principles
- 1. Reply to every comment — even if just "Done" or "Good point, fixed"
- Thank the reviewer in your first response to a review round
- Never argue — explain once, then defer to the maintainer
- Be specific — reference commits, line numbers, test names
- Respond promptly — within 24-48 hours keeps momentum
- Update PR description if the approach changed significantly
Output
- - PR URL, CI status verified
- Review responses and iterations
- Updated INLINECODE6
Tips
- - In a development pipeline, this follows dev-test and is the final delivery step.
- For managing a portfolio of PRs, run the status check periodically (or set up an automation).
- When responding to architecture concerns, creating a fresh PR (instead of force-pushing a rewrite) keeps the review history clean and makes reviewers' jobs easier.
- Always run tests locally before pushing review iterations.
PR Pilot — PR提交与全生命周期管理
概述
提交专业质量的拉取请求,并管理其从创建到合并(或关闭)的完整审查生命周期。涵盖PR创建、CI监控、审查响应、迭代和跟踪。
使用场景:开源贡献、团队代码审查、多仓库PR管理、任何代码提交流程。
前置条件
GitHub CLI必须经过身份验证——PR创建、审查监控和评论都需要它:
bash
gh auth status # 必须显示 Logged in
如果未配置,请要求用户提供:
- 1. GitHub用户名 — 用于 --head {username}:{branch} 和PR搜索
- GitHub令牌 — 运行 gh auth login 或设置 export GH_TOKEN=
令牌用于:创建PR、发布评论、检查审查状态、推送迭代更新。
第一部分:提交PR
步骤1:暂存与提交(如果尚未完成)
bash
暂存特定文件——切勿使用 git add .
git add {specific files}
git diff --cached --stat # 验证
使用约定式提交信息
git commit -m {type}({scope}): {description}
步骤2:推送到远程仓库
bash
git push origin {branch-name}
如果是新分支:
git push -u origin {branch-name}
步骤3:编写PR描述
使用此结构化模板。根据PR类型和范围调整各章节。
markdown
摘要
{1-2句话概述此PR的功能及原因}
关闭 #{issue_number}。
问题
{描述正在修复的bug/问题:}
解决方案
{技术方案描述:}
- - 架构/设计决策
- 引入的关键抽象(如有)
- 为何选择此方案而非其他方案
变更
| 文件 | 变更 |
|---|
| path/to/file.py | 新增 — 描述 |
| path/to/other.py |
修改 — 描述 |
| tests/test_file.py |
新增 — N个功能测试 |
测试
{paste test output}
N passed in X.XXs
{描述测试内容:}
向后兼容性
按PR类型调整
| PR类型 | 重点章节 | 跳过/精简 |
|---|
| Bug修复 | 问题 + 解决方案 + 测试 | 设计决策(除非不明显) |
| 功能 |
所有章节 + 可扩展性示例 | — |
| 安全修复 | 纵深防御、绕过场景、残余风险 | — |
| 重构 | 动机、前后对比 | 问题(重新表述为改进) |
步骤4:创建PR
bash
将描述保存到临时文件
cat > /tmp/pr_body.md << EOF
{pr description}
EOF
创建PR
gh pr create \
--repo {owner}/{repo} \
--head {username}:{branch} \
--base {default-branch} \
--title {type}({scope}): {description} \
--body-file /tmp/pr_body.md
步骤5:验证
bash
检查PR是否已创建
gh pr view {number} --repo {owner}/{repo} --json url,state,statusCheckRollup
验证CI是否正在运行
gh pr checks {number} --repo {owner}/{repo}
PR描述质量检查清单
- - [ ] 链接到正在修复的问题(使用 Closes #N)
- [ ] 解释根本原因,而不仅仅是症状
- [ ] 描述解决方案方法和设计决策
- [ ] 包含测试结果
- [ ] 包含文件变更汇总表
- [ ] 说明向后兼容性
第二部分:管理PR生命周期
2a. 监控PR状态
定期检查状态:
bash
单个PR
gh pr view {number} --repo {owner}/{repo} \
--json state,reviews,comments,mergeable,statusCheckRollup
所有打开的PR
gh search prs --author={username} --state=open \
--json repository,number,title,url,updatedAt
2b. 响应审查
当审查者提供反馈时,分类并响应:
模式1:可操作的代码修复
审查者:这应该处理空值情况 / 为X添加错误处理
操作:修复代码 → 添加测试 → 推送 → 回复。
好眼力——已在 {commit_sha} 中修复。添加了空值检查和一个针对此场景的测试用例。
模式2:架构问题
审查者:这种方法从根本上存在缺陷,因为...
操作:如果是根本性问题,考虑完全重构。
您说得完全正确——{确认具体问题}。我已在 #{newprnumber} 中重新设计了架构:
{新方法的简要描述}
关闭此PR,改用新方法。
重大重构步骤:
- 1. 从上游创建新分支
- 使用新方法重新实现
- 创建引用旧PR的新PR
- 关闭旧PR并添加指向新PR的评论
- 在新PR上回复审查者
模式3:风格/约定问题
审查者:我们这里使用驼峰命名 / 请添加文档字符串
操作:快速修复 → 推送 → 回复。
已在 {commit_sha} 中修复,感谢指出约定。
模式4:问题/澄清
审查者:为什么选择X而不是Y?
操作:清晰解释。如果他们建议更好的方法,则采纳。
{直接回答}。{权衡解释}。
模式5:请求添加测试
审查者:能否为边界情况添加测试...?
操作:编写测试 → 验证 → 推送 → 回复。
已在 {commit_sha} 中添加。新测试覆盖:
迭代工作流
bash
cd ~/prs/{repo}
git checkout {branch}
git pull origin {branch}
根据审查意见进行修改
...
运行测试
python -m pytest --tb=short
提交并推送
git add {files}
git commit -m address review: {description}
git push origin {branch}
2c. 处理CI失败
bash
gh pr checks {number} --repo {owner}/{repo}
在PR上评论说明 |
| CI需要配置 | 检查CONTRIBUTING.md |
| 合并冲突 | git fetch upstream && git rebase upstream/main,解决冲突,强制推送 |
2d. 跟踪进度
维护 {workspace}/pr-tracker.md 用于多PR管理:
markdown
PR活动跟踪器
最后更新:{date}
| # | 仓库 | PR | 标题 | 状态 | 问题 |
|---|
| 1 | owner/repo | #N | fix(x): desc | 🟢 打开 | #N |
| 2 |
... | ... | ... | 🟣 已合并 | #N |
状态图标:
- - 🟢 打开 — 等待审查
- 🟡 请求变更 — 需要迭代
- 🔵 已批准 — 准备合并
- 🟣 已合并
- 🔴 已关闭(未合并)
每次PR事件(创建、审查、迭代、合并、关闭)后更新跟踪器。
审查响应原则
- 1. 回复每条评论 — 即使只是已完成或好主意,已修复
- 感谢审查者 — 在首次回复审查轮次时
- 绝不争论 — 解释一次,然后遵从维护者意见
- 具体明确 — 引用提交、行号、测试名称
- 及时响应 — 24-48小时内回复以保持进度
- 更新PR描述 — 如果方法发生重大变化
输出
- - PR URL,CI状态已验证
- 审查响应和迭代
- 更新后的 pr-tracker.md
提示
- - 在开发流程中,这紧随开发-测试之后,是最终交付步骤。
- 对于管理多个PR,定期运行状态检查(或设置自动化)。
- 在回应架构问题时,创建全新的PR(而不是强制推送重写)可以保持审查历史清晰,让审查者工作更轻松。
- 在推送审查迭代之前,始终在本地运行测试。