manage-prs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseManage PRs
管理PR
Use for all operations. Stop and ask the user on: 401, 403, 422, or network timeout.
Default merge: . Check if it exists — it overrides merge defaults.
gh--squash --delete-branchAGENTS.md所有操作均使用工具。遇到401、403、422错误或网络超时,请停止操作并询问用户。
默认合并策略:。若存在文件,其内容将覆盖默认合并策略。
gh--squash --delete-branchAGENTS.mdDO NOT
禁止操作
- Explore the repo (,
ls,tree, check directories) — irrelevant to PR managementgit branch - Do exploratory research before triaging — go straight to gathering PRs
- Ask the user to confirm or choose a merge strategy — write the plan, then execute it
- Mark a PR "diff verified" without running — read every diff before classifying
gh pr diff <n> - Re-fetch individual PR metadata via when
gh pr viewalready has the dataprs.json - Merge when mergeable is — re-query until it resolves (see gotchas below)
UNKNOWN
- 探索仓库(执行、
ls、tree命令,查看目录)——这与PR管理无关git branch - 在分类前进行探索性研究——直接获取PR信息即可
- 要求用户确认或选择合并策略——制定计划后直接执行
- 未运行就标记PR“差异已验证”——分类前需查看每一处差异
gh pr diff <n> - 当已包含数据时,通过
prs.json重新获取单个PR元数据gh pr view - 当mergeable状态为时进行合并——重新查询直到状态明确(详见下方常见陷阱)
UNKNOWN
Gotchas
常见陷阱
UNKNOWNgh pr view <n> --json mergeableUNKNOWN--json commentsgh pr view--json body,comments--commentsgh pr update-branchgh api repos/{owner}/{repo}/pulls/{n}/update-branch -f merge_method=squashgh pr list--limit 100Always comment when closing. — never silently.
gh pr close <n> --comment "Closing because..."gh pr create--body-file--body-file--body"Base branch was modified" on merge. Each merge changes the base branch, so the next merge may fail.
Merge PRs one at a time. On this error, simply retry the same merge command.
UNKNOWNgh pr view <n> --json mergeableUNKNOWN--json commentsgh pr view--json body,comments--commentsgh pr update-branchgh api repos/{owner}/{repo}/pulls/{n}/update-branch -f merge_method=squashgh pr list--limit 100关闭PR时必须添加评论。 ——绝对不要静默关闭。
gh pr close <n> --comment "Closing because..."gh pr create--body-file--body-file--body合并时出现“Base branch was modified”错误。 每次合并都会修改基准分支,因此下一次合并可能失败。
请逐个合并PR。遇到此错误时,只需重试相同的合并命令即可。
Single-PR Workflow
单个PR处理流程
Use when the user names a specific PR (e.g. "merge PR #42", "close PR #7").
- Health check: — Verify mergeable is
gh pr view <n> --json number,title,author,isDraft,mergeable,reviewDecision,statusCheckRollup,body. IfMERGEABLE, re-query up to 3×.UNKNOWN - Read diff: — verify logic, imports, API usage. For bot/AI PRs, grep unfamiliar identifiers.
gh pr diff <n> - Act: merge (), close with comment, or hand off to
gh pr merge <n> --squash --delete-branch.review-pr
当用户指定具体PR时使用(例如“合并PR #42”“关闭PR #7”)。
- 健康检查:执行——验证mergeable状态为
gh pr view <n> --json number,title,author,isDraft,mergeable,reviewDecision,statusCheckRollup,body。若为MERGEABLE,最多重新查询3次。UNKNOWN - 查看差异:执行——验证逻辑、导入项、API使用是否正确。对于机器人/AI生成的PR,需搜索陌生标识符。
gh pr diff <n> - 执行操作:合并()、添加评论后关闭,或移交至
gh pr merge <n> --squash --delete-branch处理。review-pr
Batch Triage Workflow
批量PR分类流程
Use when managing multiple PRs (e.g. "triage PRs", "clean up PR queue").
当管理多个PR时使用(例如“分类PR”“清理PR队列”)。
Step 1: Gather and detect overlaps
步骤1:收集PR并检测文件重叠
bash
gh pr list --json number,title,author,isDraft,mergeable,reviewDecision,statusCheckRollup,baseRefName,files \
--limit 100 | tee prs.json | python3 -c "
import json, sys, collections
data = json.load(sys.stdin)
by_file = collections.defaultdict(list)
for pr in data:
for f in pr.get('files', []):
if isinstance(f, dict) and 'path' in f:
by_file[f['path']].append(pr['number'])
overlaps = [(p, ns) for p, ns in by_file.items() if len(ns) > 1]
if overlaps:
print('OVERLAPPING FILES:')
for p, ns in sorted(overlaps, key=lambda x: -len(x[1])):
print(f' {p}: PRs {ns}')
else:
print('No file overlaps detected.')
"This saves AND pipes to overlap detection in one shot.
Overlapping PRs need sequenced merging — merge the simpler one first, re-check conflicts on the other.
Also read for merge overrides if it exists.
prs.jsonAGENTS.mdbash
gh pr list --json number,title,author,isDraft,mergeable,reviewDecision,statusCheckRollup,baseRefName,files \
--limit 100 | tee prs.json | python3 -c "
import json, sys, collections
data = json.load(sys.stdin)
by_file = collections.defaultdict(list)
for pr in data:
for f in pr.get('files', []):
if isinstance(f, dict) and 'path' in f:
by_file[f['path']].append(pr['number'])
overlaps = [(p, ns) for p, ns in by_file.items() if len(ns) > 1]
if overlaps:
print('OVERLAPPING FILES:')
for p, ns in sorted(overlaps, key=lambda x: -len(x[1])):
print(f' {p}: PRs {ns}')
else:
print('No file overlaps detected.')
"此命令会保存文件,同时完成文件重叠检测。
存在重叠的PR需要按顺序合并——先合并较简单的PR,再重新检查另一个PR的冲突。
若存在文件,需查看其中的合并覆盖规则。
prs.jsonAGENTS.mdStep 2: Read every diff
步骤2:查看每一处差异
For each PR, run and verify logic, imports, no obvious breakage.
For bot/AI PRs, grep unfamiliar identifiers in the codebase.
Do NOT skip this step — a PR cannot be classified as merge-ready without a diff read.
gh pr diff <n>对每个PR执行,验证逻辑、导入项是否正确,无明显问题。
对于机器人/AI生成的PR,需在代码库中搜索陌生标识符。
绝对不要跳过此步骤——未查看差异的PR不能被归类为可合并状态。
gh pr diff <n>Step 3: Triage report
步骤3:分类报告
Use data from (mergeability, CI, review) plus your diff reads to classify each PR.
Write results to a plan file:
prs.json- ✅ Merge-ready — , CI green, diff read and verified
MERGEABLE - ⚠️ Needs action — blocked by conflict / CI / review
- 🔁 Stale — no activity >14 days
- 🔀 Overlapping — file conflict risk with merge order specified
- ❌ Close candidates — superseded, duplicate, or abandoned
After writing the plan, proceed to merge — do not stop and ask for confirmation.
结合中的数据(合并状态、CI状态、审核结果)以及差异查看结果,对每个PR进行分类。
将结果写入计划文件:
prs.json- ✅ 可合并 ——状态、CI通过、已查看并验证差异
MERGEABLE - ⚠️ 需处理 ——存在冲突/CI失败/待审核
- 🔁 陈旧 ——超过14天无活动
- 🔀 重叠 ——存在文件冲突风险,需指定合并顺序
- ❌ 建议关闭 ——已被替代、重复或已废弃
编写完计划后直接执行合并操作——无需停止并请求确认。
Cross-Skill Routing
跨技能路由
| Situation | Hand off to |
|---|---|
| PR needs structured code review before merge | |
| PR has unresolved review threads to address | |
| 场景 | 移交至 |
|---|---|
| PR合并前需要结构化代码审核 | |
| PR存在未解决的审核反馈 | |