1k-monitor-pr-ci
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMonitor 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$ARGUMENTSWorkflow
工作流
Step 1: Resolve PR number
步骤1:解析PR编号
Determine the PR to monitor:
- If is a number, use it directly
$ARGUMENTS - If is a GitHub URL, extract the PR number
$ARGUMENTS - If is empty, detect from current branch:
$ARGUMENTSbashgh pr list --head "$(git branch --show-current)" --json number --jq '.[0].number' - If no PR found, stop and inform the user
确定需要监控的PR:
- 如果为数字,直接使用
$ARGUMENTS - 如果为GitHub URL,提取PR编号
$ARGUMENTS - 如果为空,从当前分支检测:
$ARGUMENTSbashgh pr list --head "$(git branch --show-current)" --json number --jq '.[0].number' - 未找到对应PR则停止运行并通知用户
Step 2: Poll loop
步骤2:轮询循环
Each iteration ():
[Check N/30]-
Fetch CI status:bash
gh pr checks <PR_NUMBER> -
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}' -
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 -
Decide next action based on priority:
CI Status Reviews Action Any fail - Auto-fix CI failure (Step 3) Any pending New comments Show comments to user, keep waiting Any pending No new comments Wait 60s, re-check All pass New comments Show comments to user (Step 4) All pass No new comments Done (Step 5)
每次迭代():
[检查 N/30]-
获取CI状态:bash
gh pr checks <PR_NUMBER> -
获取评审评论(每次迭代都执行):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/30] CI状态: | 检查项 | 状态 | 耗时 | |------------------|---------|----------| | lint (24.x) | 已通过 | 5分34秒 | | unittest (24.x) | 处理中 | - | 评审:来自@reviewer的1条新评论 -
根据优先级决定下一步操作:
CI状态 评审 操作 任意检查失败 - 自动修复 CI故障(步骤3) 存在处理中检查 有新评论 向用户展示评论,继续等待 存在处理中检查 无新评论 等待60秒后重新检查 全部检查通过 有新评论 向用户展示评论(步骤4) 全部检查通过 无新评论 完成(步骤5)
Step 3: Auto-fix CI failures
步骤3:自动修复CI故障
For each failed check:
-
Get failure log:bash
gh run view <RUN_ID> --log-failed 2>&1 | tail -100Extract the run ID from the check URL. -
Analyze the failure and determine the cause.
-
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
-
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
针对每个失败的检查:
-
获取失败日志:bash
gh run view <RUN_ID> --log-failed 2>&1 | tail -100从检查URL中提取运行ID。 -
分析故障确定原因。
-
可修复(lint错误、类型错误、本次改动导致的测试失败):
- 修复代码
- 提交信息:
fix: resolve CI <check-name> failure - 推送到PR分支
- 等待30秒,返回步骤2
-
不可修复(基础设施问题、不稳定测试、不相关故障):
- 向用户报告故障详情
- 建议操作(重新运行、跳过、手动修复)
- 询问用户后续处理方式
Step 4: Handle review comments
步骤4:处理评审评论
When new review comments are detected:
-
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 -
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
-
Track comment state: Remember which comments have been shown to avoid repeating them in subsequent iterations.
检测到新的评审评论时:
-
清晰展示每条评论:
来自@reviewer的新评审评论: 文件:src/views/Example.tsx:42 > 建议在此处使用useCallback避免重复渲染 评审结论:CHANGES_REQUESTED -
提示用户:
- 展示所有未解决的评论
- 询问:「是否需要我处理这些评审评论?」
- 用户同意:修复代码、提交、推送,返回步骤2
- 用户拒绝/稍后处理:仅继续监控CI
-
追踪评论状态:记录已向用户展示过的评论,避免后续迭代重复展示。
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