1k-monitor-pr-ci

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Monitor PR CI & Reviews

监控PR CI与评审

Monitor a pull request's CI checks and review comments. Auto-fix CI failures, prompt user for review feedback.
监控拉取请求的CI检查和评审评论。自动修复CI故障,提示用户处理评审反馈。

Input

输入

$ARGUMENTS
- PR number, PR URL, or omit to auto-detect from current branch.
$ARGUMENTS
- PR编号、PR URL,若省略则自动从当前分支检测。

Workflow

工作流

Step 1: Resolve PR number

步骤1:解析PR编号

Determine the PR to monitor:
  • If
    $ARGUMENTS
    is a number, use it directly
  • If
    $ARGUMENTS
    is a GitHub URL, extract the PR number
  • If
    $ARGUMENTS
    is empty, detect from current branch:
    bash
    gh pr list --head "$(git branch --show-current)" --json number --jq '.[0].number'
  • If no PR found, stop and inform the user
确定需要监控的PR:
  • 如果
    $ARGUMENTS
    为数字,直接使用
  • 如果
    $ARGUMENTS
    为GitHub URL,提取PR编号
  • 如果
    $ARGUMENTS
    为空,从当前分支检测:
    bash
    gh pr list --head "$(git branch --show-current)" --json number --jq '.[0].number'
  • 未找到对应PR则停止运行并通知用户

Step 2: Poll loop

步骤2:轮询循环

Each iteration (
[Check N/30]
):
  1. Fetch CI status:
    bash
    gh pr checks <PR_NUMBER>
  2. Fetch review comments (every iteration):
    bash
    gh pr view <PR_NUMBER> --json reviews,comments,reviewDecision
    gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments --jq '.[] | {user: .user.login, body: .body, path: .path, line: .original_line, created_at: .created_at}'
  3. Display status summary:
    [Check 3/30]
    
    CI Status:
    | Check            | Status  | Duration |
    |------------------|---------|----------|
    | lint (24.x)      | pass    | 5m34s    |
    | unittest (24.x)  | pending | -        |
    
    Reviews: 1 new comment from @reviewer
  4. Decide next action based on priority:
    CI StatusReviewsAction
    Any fail-Auto-fix CI failure (Step 3)
    Any pendingNew commentsShow comments to user, keep waiting
    Any pendingNo new commentsWait 60s, re-check
    All passNew commentsShow comments to user (Step 4)
    All passNo new commentsDone (Step 5)
每次迭代(
[检查 N/30]
):
  1. 获取CI状态
    bash
    gh pr checks <PR_NUMBER>
  2. 获取评审评论(每次迭代都执行):
    bash
    gh pr view <PR_NUMBER> --json reviews,comments,reviewDecision
    gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments --jq '.[] | {user: .user.login, body: .body, path: .path, line: .original_line, created_at: .created_at}'
  3. 展示状态概览
    [检查 3/30]
    
    CI状态:
    | 检查项            | 状态   | 耗时 |
    |------------------|---------|----------|
    | lint (24.x)      | 已通过    | 5分34秒    |
    | unittest (24.x)  | 处理中 | -        |
    
    评审:来自@reviewer的1条新评论
  4. 根据优先级决定下一步操作
    CI状态评审操作
    任意检查失败-自动修复 CI故障(步骤3)
    存在处理中检查有新评论向用户展示评论,继续等待
    存在处理中检查无新评论等待60秒后重新检查
    全部检查通过有新评论向用户展示评论(步骤4)
    全部检查通过无新评论完成(步骤5)

Step 3: Auto-fix CI failures

步骤3:自动修复CI故障

For each failed check:
  1. Get failure log:
    bash
    gh run view <RUN_ID> --log-failed 2>&1 | tail -100
    Extract the run ID from the check URL.
  2. Analyze the failure and determine the cause.
  3. Fixable (lint error, type error, test failure from our changes):
    • Fix the code
    • Commit:
      fix: resolve CI <check-name> failure
    • Push to PR branch
    • Wait 30s, return to Step 2
  4. Not fixable (infra issue, flaky test, unrelated failure):
    • Report failure details to user
    • Suggest actions (re-run, skip, manual fix)
    • Ask user how to proceed
针对每个失败的检查:
  1. 获取失败日志:
    bash
    gh run view <RUN_ID> --log-failed 2>&1 | tail -100
    从检查URL中提取运行ID。
  2. 分析故障确定原因。
  3. 可修复(lint错误、类型错误、本次改动导致的测试失败):
    • 修复代码
    • 提交信息:
      fix: resolve CI <check-name> failure
    • 推送到PR分支
    • 等待30秒,返回步骤2
  4. 不可修复(基础设施问题、不稳定测试、不相关故障):
    • 向用户报告故障详情
    • 建议操作(重新运行、跳过、手动修复)
    • 询问用户后续处理方式

Step 4: Handle review comments

步骤4:处理评审评论

When new review comments are detected:
  1. Display each comment clearly:
    New review comment from @reviewer:
    File: src/views/Example.tsx:42
    > Consider using useCallback here to prevent re-renders
    
    Review decision: CHANGES_REQUESTED
  2. Prompt the user:
    • Show all unresolved comments
    • Ask: "Do you want me to address these review comments?"
    • If user says yes: fix the code, commit, push, return to Step 2
    • If user says no/later: continue monitoring CI only
  3. Track comment state: Remember which comments have been shown to avoid repeating them in subsequent iterations.
检测到新的评审评论时:
  1. 清晰展示每条评论
    来自@reviewer的新评审评论:
    文件:src/views/Example.tsx:42
    > 建议在此处使用useCallback避免重复渲染
    
    评审结论:CHANGES_REQUESTED
  2. 提示用户
    • 展示所有未解决的评论
    • 询问:「是否需要我处理这些评审评论?」
    • 用户同意:修复代码、提交、推送,返回步骤2
    • 用户拒绝/稍后处理:仅继续监控CI
  3. 追踪评论状态:记录已向用户展示过的评论,避免后续迭代重复展示。

Step 5: Final report

步骤5:最终报告

When all CI checks pass and no new unhandled comments:
All CI checks passed!

| Check            | Status | Duration |
|------------------|--------|----------|
| lint (24.x)      | pass   | 5m34s    |
| unittest (24.x)  | pass   | 4m42s    |
| CodeQL           | pass   | 2m7s     |

Review status: approved / no reviews / changes requested
PR: <URL>
  • All CI passed + approved → ready to merge
  • All CI passed + no review → waiting for review
  • All CI passed + changes requested → needs to address comments
所有CI检查通过且无未处理的新评论时:
所有CI检查已通过!

| 检查项            | 状态 | 耗时 |
|------------------|--------|----------|
| lint (24.x)      | 已通过   | 5分34秒    |
| unittest (24.x)  | 已通过   | 4分42秒    |
| CodeQL           | 已通过   | 2分7秒     |

评审状态:已批准 / 无评审 / 请求修改
PR:<URL>
  • 所有CI通过+已批准 → 可合并
  • 所有CI通过+无评审 → 等待评审
  • 所有CI通过+请求修改 → 需要处理评论

Polling Rules

轮询规则

  • 60 seconds between checks when pending
  • 30 seconds after fix+push to allow CI restart
  • Maximum 30 iterations (~30 min), then ask user to continue or stop
  • Always show
    [Check N/30]
  • 存在待处理检查时每60秒检查一次
  • 修复并推送后等待30秒供CI重启
  • 最多执行30次迭代(约30分钟),之后询问用户继续还是停止
  • 始终展示
    [检查 N/30]
    标识

Important Notes

重要注意事项

  • CI failures: auto-fix without asking
  • Review comments: always show to user, ask before fixing
  • Never force-push or amend commits
  • Each fix is a new commit
  • Fix multiple CI failures in one commit when possible
  • Do NOT re-run checks automatically (only if user requests
    gh run rerun
    )
  • CI故障:无需询问直接自动修复
  • 评审评论:始终向用户展示,修复前必须征求用户同意
  • 绝不强制推送或修改已有提交
  • 每个修复对应一个新的提交
  • 尽可能在一次提交中修复多个CI故障
  • 不得自动重新运行检查(仅当用户要求执行
    gh run rerun
    时才操作)