iterate-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Iterate on PR Until CI Passes

持续迭代PR直至CI检查通过

Continuously iterate on the current branch until all CI checks pass and review feedback is addressed.
Requires: GitHub CLI (
gh
) authenticated and available.
持续迭代当前分支,直至所有CI检查通过且评审反馈得到处理。
前置要求:已完成GitHub CLI(
gh
)的认证且可正常使用。

Process

流程

Step 1: Identify the PR

步骤1:识别PR

bash
gh pr view --json number,url,headRefName,baseRefName
If no PR exists for the current branch, stop and inform the user.
bash
gh pr view --json number,url,headRefName,baseRefName
如果当前分支不存在对应的PR,请停止操作并通知用户。

Step 2: Check CI Status First

步骤2:先检查CI状态

Always check CI/GitHub Actions status before looking at review feedback:
bash
gh pr checks --json name,state,bucket,link,workflow
The
bucket
field categorizes state into:
pass
,
fail
,
pending
,
skipping
, or
cancel
.
Important: If any of these checks are still
pending
, wait before proceeding:
  • sentry
    /
    sentry-io
  • codecov
  • cursor
    /
    bugbot
    /
    seer
  • Any linter or code analysis checks
These bots may post additional feedback comments once their checks complete. Waiting avoids duplicate work.
在查看评审反馈前,务必先检查CI/GitHub Actions的状态:
bash
gh pr checks --json name,state,bucket,link,workflow
bucket
字段会将状态分为:
pass
(通过)、
fail
(失败)、
pending
(待处理)、
skipping
(跳过)或
cancel
(取消)。
重要提示:如果以下任意检查仍处于
pending
状态,请等待其完成后再继续:
  • sentry
    /
    sentry-io
  • codecov
  • cursor
    /
    bugbot
    /
    seer
  • 任何代码检查或代码分析类检查
这些机器人完成检查后可能会发布额外的反馈评论。等待可避免重复工作。

Step 3: Gather Review Feedback

步骤3:收集评审反馈

Once CI checks have completed (or at least the bot-related checks), gather human and bot feedback:
Review Comments and Status:
bash
gh pr view --json reviews,comments,reviewDecision
Inline Code Review Comments:
bash
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments
PR Conversation Comments (includes bot comments):
bash
gh api repos/{owner}/{repo}/issues/{pr_number}/comments
Look for bot comments from: Sentry, Codecov, Cursor, Bugbot, Seer, and other automated tools.
当CI检查完成(至少是机器人相关的检查完成)后,收集人工和机器人的反馈:
评审评论与状态
bash
gh pr view --json reviews,comments,reviewDecision
行内代码评审评论
bash
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments
PR对话评论(包含机器人评论)
bash
gh api repos/{owner}/{repo}/issues/{pr_number}/comments
留意来自以下机器人的评论:Sentry、Codecov、Cursor、Bugbot、Seer以及其他自动化工具。

Step 4: Investigate Failures

步骤4:排查失败原因

For each CI failure, get the actual logs:
bash
undefined
针对每一项CI失败,获取实际日志:
bash
undefined

List recent runs for this branch

列出当前分支的最近运行记录

gh run list --branch $(git branch --show-current) --limit 5 --json databaseId,name,status,conclusion
gh run list --branch $(git branch --show-current) --limit 5 --json databaseId,name,status,conclusion

View failed logs for a specific run

查看特定运行记录的失败日志

gh run view <run-id> --log-failed

Do NOT assume what failed based on the check name alone. Always read the actual logs.
gh run view <run-id> --log-failed

**请勿**仅根据检查名称假设失败原因。务必查看实际日志。

Step 5: Validate Feedback

步骤5:验证反馈

For each piece of feedback (CI failure or review comment):
  1. Read the relevant code - Understand the context before making changes
  2. Verify the issue is real - Not all feedback is correct; reviewers and bots can be wrong
  3. Check if already addressed - The issue may have been fixed in a subsequent commit
  4. Skip invalid feedback - If the concern is not legitimate, move on
针对每一条反馈(CI失败或评审评论):
  1. 阅读相关代码 - 在进行修改前先理解上下文
  2. 验证问题是否真实存在 - 并非所有反馈都是正确的;评审人员和机器人也可能出错
  3. 检查问题是否已被处理 - 该问题可能已在后续提交中修复
  4. 跳过无效反馈 - 如果问题不合理,请直接跳过

Step 6: Address Valid Issues

步骤6:处理有效问题

Make minimal, targeted code changes. Only fix what is actually broken.
进行最小化、针对性的代码修改。仅修复实际存在的问题。

Step 7: Commit and Push

步骤7:提交并推送

bash
git add -A
git commit -m "fix: <descriptive message of what was fixed>"
git push
bash
git add -A
git commit -m "fix: <描述修复内容的信息>"
git push

Step 8: Wait for CI

步骤8:等待CI完成

Use the built-in watch functionality:
bash
gh pr checks --watch --interval 30
This waits until all checks complete. Exit code 0 means all passed, exit code 1 means failures.
Alternatively, poll manually if you need more control:
bash
gh pr checks --json name,state,bucket | jq '.[] | select(.bucket != "pass")'
使用内置的监控功能:
bash
gh pr checks --watch --interval 30
该命令会等待所有检查完成。退出码0表示所有检查通过,退出码1表示存在失败。
如果需要更多控制权,也可以手动轮询:
bash
gh pr checks --json name,state,bucket | jq '.[] | select(.bucket != "pass")'

Step 9: Repeat

步骤9:重复操作

Return to Step 2 if:
  • Any CI checks failed
  • New review feedback appeared
Continue until all checks pass and no unaddressed feedback remains.
如果出现以下情况,请返回步骤2:
  • 任何CI检查失败
  • 出现新的评审反馈
持续重复操作,直至所有检查通过且无未处理的反馈。

Exit Conditions

退出条件

Success:
  • All CI checks are green (
    bucket: pass
    )
  • No unaddressed human review feedback
Ask for Help:
  • Same failure persists after 3 attempts (likely a flaky test or deeper issue)
  • Review feedback requires clarification or decision from the user
  • CI failure is unrelated to branch changes (infrastructure issue)
Stop Immediately:
  • No PR exists for the current branch
  • Branch is out of sync and needs rebase (inform user)
成功退出
  • 所有CI检查均通过(
    bucket: pass
  • 无未处理的人工评审反馈
请求帮助
  • 同一失败问题在3次尝试后仍存在(可能是不稳定测试或更深层次的问题)
  • 评审反馈需要用户澄清或做出决策
  • CI失败与分支修改无关(基础设施问题)
立即停止
  • 当前分支不存在对应的PR
  • 分支与上游不同步,需要重新合并(通知用户)

Tips

提示

  • Use
    gh pr checks --required
    to focus only on required checks
  • Use
    gh run view <run-id> --verbose
    to see all job steps, not just failures
  • If a check is from an external service, the
    link
    field in checks JSON provides the URL to investigate
  • 使用
    gh pr checks --required
    仅关注必填检查项
  • 使用
    gh run view <run-id> --verbose
    查看所有作业步骤,而非仅失败步骤
  • 如果检查来自外部服务,检查结果JSON中的
    link
    字段提供了用于排查的URL