github-pr-agent-workflows

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub PR Agent Workflows

GitHub PR Agent工作流

Overview

概述

Use this skill for agent-oriented pull request loops: prepare the PR, wait for checks, wait for review activity, inspect feedback, make follow-up changes, and report the final state. Prefer the bundled scripts for repeatable review polling and review-thread summaries.
本技能适用于面向Agent的拉取请求循环:准备PR、等待检查、等待审核活动、查看反馈、进行后续变更并报告最终状态。对于可重复的审核轮询和审核线程汇总,建议使用捆绑的脚本。

Quick Commands

快速命令

Watch checks, then review activity:
bash
scripts/pr-agent-watch.sh 123 -R OWNER/REPO --checks-timeout 30m --review-timeout 2h
Wait for review activity:
bash
scripts/wait-pr-review.sh 123 -R OWNER/REPO --timeout 30m --interval 60s
Summarize current review state:
bash
scripts/pr-review-summary.sh 123 -R OWNER/REPO
Print parseable review state:
bash
scripts/pr-review-summary.sh 123 -R OWNER/REPO --json
Wait for CI checks with
gh
:
bash
gh pr checks 123 -R OWNER/REPO --watch --interval 10
Use the system
timeout
command when a bounded check wait is required:
bash
timeout 30m gh pr checks 123 -R OWNER/REPO --watch --interval 10
监控检查,然后监控审核活动:
bash
scripts/pr-agent-watch.sh 123 -R OWNER/REPO --checks-timeout 30m --review-timeout 2h
等待审核活动:
bash
scripts/wait-pr-review.sh 123 -R OWNER/REPO --timeout 30m --interval 60s
汇总当前审核状态:
bash
scripts/pr-review-summary.sh 123 -R OWNER/REPO
输出可解析的审核状态:
bash
scripts/pr-review-summary.sh 123 -R OWNER/REPO --json
使用
gh
等待CI检查:
bash
gh pr checks 123 -R OWNER/REPO --watch --interval 10
当需要限定检查等待时间时,使用系统
timeout
命令:
bash
timeout 30m gh pr checks 123 -R OWNER/REPO --watch --interval 10

Agent Loop

Agent循环

  1. Identify the PR and repository. Use
    gh pr view --json number,url,headRefName,baseRefName,reviewDecision,mergeStateStatus,statusCheckRollup
    or accept an explicit PR number and
    -R OWNER/REPO
    .
  2. Snapshot the PR before waiting. Run
    scripts/pr-review-summary.sh
    when review feedback may matter.
  3. Wait for CI when validation gates the next action. Use
    scripts/pr-agent-watch.sh
    when the agent should wait for checks and review feedback in one loop. Use
    gh pr checks --watch
    for checks-only waits.
  4. Wait for reviewer activity when the next action depends on feedback. Use
    scripts/wait-pr-review.sh
    ; prefer
    --ignore-existing
    after the agent has already handled current feedback.
  5. Inspect comments before editing. Use the review summary script, preferably with
    --json
    when automation needs to parse unresolved threads. Use
    gh pr view --comments
    or
    gh api repos/{owner}/{repo}/pulls/{pull_number}/comments --paginate
    when bodies or locations need deeper inspection.
  6. Address feedback in a small patch. Do not rewrite unrelated files. Preserve user changes in the worktree.
  7. Run the relevant checks locally. Keep validation proportional to the changed area.
  8. Push or report. Push only when that is part of the task. Merge only when the user explicitly asked for merge behavior.
  1. 确定PR和仓库。 使用
    gh pr view --json number,url,headRefName,baseRefName,reviewDecision,mergeStateStatus,statusCheckRollup
    命令,或者直接指定PR编号和
    -R OWNER/REPO
    参数。
  2. 在等待前快照PR状态。 若审核反馈很重要,运行
    scripts/pr-review-summary.sh
    脚本。
  3. 当验证环节会影响下一步操作时,等待CI完成。 若Agent需要在一个循环中同时等待检查和审核反馈,使用
    scripts/pr-agent-watch.sh
    脚本。仅需等待检查时,使用
    gh pr checks --watch
    命令。
  4. 当下一步操作依赖反馈时,等待审核者活动。 使用
    scripts/wait-pr-review.sh
    脚本;若Agent已处理当前反馈,建议添加
    --ignore-existing
    参数。
  5. 在编辑前查看评论。 使用审核汇总脚本,若自动化需要解析未解决线程,建议添加
    --json
    参数。若需要深入查看评论内容或位置,使用
    gh pr view --comments
    gh api repos/{owner}/{repo}/pulls/{pull_number}/comments --paginate
    命令。
  6. 以小补丁形式处理反馈。 不要重写无关文件,保留工作区中的用户变更。
  7. 本地运行相关检查。 验证范围与变更区域相匹配。
  8. 推送或报告状态。 仅当任务要求时才推送代码。仅当用户明确要求合并操作时才执行合并。

Decision Rules

决策规则

  • If checks fail, inspect the failing check logs before changing code.
  • If
    wait-pr-review.sh
    exits
    0
    , inspect review threads and review decisions before editing.
  • If
    wait-pr-review.sh
    exits
    124
    , report that no matching review activity arrived before the timeout.
  • If
    gh pr checks --watch
    exits because checks are still pending or the wrapper timeout fires, report the pending state instead of guessing.
  • If the PR is approved and checks pass, stop unless the user asked for merge or follow-up automation.
  • If review feedback conflicts with the user request, summarize the conflict and ask before making a risky change.
  • 如果检查失败,在修改代码前先查看失败检查的日志。
  • 如果
    wait-pr-review.sh
    脚本返回退出码
    0
    ,在编辑前先查看审核线程和审核决策。
  • 如果
    wait-pr-review.sh
    脚本返回退出码
    124
    ,报告在超时前未收到匹配的审核活动。
  • 如果
    gh pr checks --watch
    因检查仍在进行或包装超时而退出,报告待处理状态而非猜测结果。
  • 如果PR已获批准且检查通过,除非用户要求合并或后续自动化操作,否则停止流程。
  • 如果审核反馈与用户请求冲突,汇总冲突情况并在进行风险变更前询问用户。

Bundled Scripts

捆绑脚本

scripts/pr-agent-watch.sh

scripts/pr-agent-watch.sh

Wait for PR checks, then wait for review activity and print a review summary when feedback arrives.
Common options:
  • --checks-timeout 30m
  • --checks-interval 10s
  • --review-timeout 2h
  • --review-interval 60s
  • --review-mode any|comments|review|approval|changes-requested
  • --ignore-existing-review
  • --skip-checks
  • --skip-review
Exit codes:
  • 0
    : ready; checks passed and review wait was skipped
  • 10
    : review activity found and summarized
  • 20
    : checks failed or were cancelled
  • 21
    : checks timed out
  • 22
    : review wait timed out
  • 2
    : usage, PR resolution, or GitHub API error
等待PR检查完成,然后等待审核活动,当收到反馈时输出审核汇总。
常用选项:
  • --checks-timeout 30m
  • --checks-interval 10s
  • --review-timeout 2h
  • --review-interval 60s
  • --review-mode any|comments|review|approval|changes-requested
  • --ignore-existing-review
  • --skip-checks
  • --skip-review
退出码:
  • 0
    : 就绪;检查通过且跳过审核等待
  • 10
    : 发现审核活动并已汇总
  • 20
    : 检查失败或被取消
  • 21
    : 检查超时
  • 22
    : 审核等待超时
  • 2
    : 使用错误、PR解析错误或GitHub API错误

scripts/wait-pr-review.sh

scripts/wait-pr-review.sh

Poll a pull request until matching review activity appears or the timeout expires.
Common options:
  • --timeout 30m
  • --interval 60s
  • --mode any|comments|review|approval|changes-requested
  • --ignore-existing
Exit codes:
  • 0
    : matching review activity found
  • 124
    : timeout
  • 2
    : usage, PR resolution, or GitHub API error
轮询拉取请求,直到出现匹配的审核活动或超时。
常用选项:
  • --timeout 30m
  • --interval 60s
  • --mode any|comments|review|approval|changes-requested
  • --ignore-existing
退出码:
  • 0
    : 发现匹配的审核活动
  • 124
    : 超时
  • 2
    : 使用错误、PR解析错误或GitHub API错误

scripts/pr-review-summary.sh

scripts/pr-review-summary.sh

Print PR state, latest reviews, pending review requests, and unresolved review threads with file locations and comment URLs. Use
--json
for parseable output that includes unresolved thread counts, comment URLs, authors, timestamps, and bodies.
输出PR状态、最新审核记录、待处理审核请求,以及包含文件位置和评论链接的未解决审核线程。使用
--json
参数可输出可解析的结果,其中包含未解决线程数量、评论链接、作者、时间戳和评论内容。