check-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Check PR

检查PR

Analyze a pull request for review comments, status checks, and description completeness, then help address any issues found.
分析拉取请求(PR)的评审评论、状态检查和描述完整性,随后协助解决发现的所有问题。

Inputs

输入项

  • PR number (optional): If not provided, detect the PR for the current branch.
  • PR编号(可选):如果未提供,则自动检测当前分支对应的PR。

Instructions

操作步骤

1. Identify the PR

1. 确定PR

If a PR number was provided, use it. Otherwise, detect it:
bash
gh pr view --json number -q .number
如果提供了PR编号,则使用该编号。否则,自动检测:
bash
gh pr view --json number -q .number

2. Fetch PR details

2. 获取PR详情

bash
gh pr view <PR_NUMBER> --json title,body,state,reviews,comments,headRefName,statusCheckRollup
gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments
bash
gh pr view <PR_NUMBER> --json title,body,state,reviews,comments,headRefName,statusCheckRollup
gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments

3. Wait for pending checks

3. 等待待处理检查完成

Before analyzing, ensure all status checks have completed. If any checks are
PENDING
or
IN_PROGRESS
, poll every 30 seconds until all checks reach a terminal state (success or failure). This ensures that review bot comments (Greptile, linters, etc.) are available before analysis.
在分析之前,确保所有状态检查已完成。如果存在任何处于
PENDING
(待处理)或
IN_PROGRESS
(进行中)状态的检查,每30秒轮询一次,直到所有检查进入终端状态(成功或失败)。这可以确保分析前能获取到评审机器人(如Greptile、代码检查工具等)的评论。

4. Analyze the PR

4. 分析PR

Once all checks are complete, evaluate these areas:
所有检查完成后,对以下方面进行评估:

A. Status Checks

A. 状态检查

  • Are all CI checks passing?
  • If any are failing, identify which ones and the failure reason.
  • 所有CI检查是否都已通过?
  • 如果有检查失败,确定是哪些检查以及失败原因。

B. PR Description

B. PR描述

  • Is the description complete and follows team conventions?
  • Are all required sections filled in?
  • Are there TODOs or placeholders that need updating?
  • 描述是否完整且符合团队规范?
  • 所有必填部分是否已填写?
  • 是否存在需要更新的TODO项或占位符?

C. Review Comments

C. 评审评论

  • Inline code review comments that need addressing
  • Look for bot review comments (e.g. from
    greptile-apps[bot]
    , linters, etc.)
  • Human reviewer comments
  • 需要处理的内联代码评审评论
  • 查找机器人评审评论(如来自
    greptile-apps[bot]
    、代码检查工具等的评论)
  • 人工评审者的评论

D. General Comments

D. 通用评论

  • Discussion comments on the PR
  • Bot comments (Vercel deploy previews, etc.) — usually informational
  • PR上的讨论类评论
  • 机器人评论(如Vercel部署预览等)——通常为信息类评论

5. Categorize issues

5. 分类问题

For each issue found, categorize as:
CategoryMeaning
ActionableCode changes, test improvements, or fixes needed
InformationalVerification notes, questions, or FYIs that don't require changes
Already addressedIssues that appear to be resolved by subsequent commits
对发现的每个问题进行分类:
分类含义
可操作类需要修改代码、改进测试或进行修复
信息类验证说明、疑问或仅供参考的内容,无需修改
已处理后续提交似乎已解决的问题

6. Report findings

6. 汇报结果

Present a summary table:
AreaIssueStatusAction Needed
Status ChecksCI build failingFailingFix type error in
src/api.ts
Review"Add null check" — @reviewerActionableAdd guard clause
DescriptionTODO placeholder in test planActionableFill in test plan
Review"Looks good" — @teammateInformationalNone
呈现汇总表格:
领域问题状态所需操作
状态检查CI构建失败失败修复
src/api.ts
中的类型错误
评审"添加空值检查" — @评审者可操作添加保护子句
描述测试计划中存在TODO占位符可操作完善测试计划
评审"看起来不错" — @团队成员信息类

7. Fix issues (if requested)

7. 修复问题(若有需求)

If there are actionable items:
  1. Switch to the PR's branch if not already on it.
  2. Ask the user if they want to fix the issues.
  3. If yes, make the fixes, commit, and push.
如果存在可操作项:
  1. 若当前未处于PR分支,则切换到该分支。
  2. 询问用户是否需要修复这些问题。
  3. 如果用户同意,进行修复、提交并推送代码。

8. Resolve review threads

8. 解决评审线程

After addressing comments, resolve the corresponding review threads.
First, fetch unresolved thread IDs (paginate if needed — see the GraphQL reference):
bash
gh api graphql -f query='
query($cursor: String) {
  repository(owner: "OWNER", name: "REPO") {
    pullRequest(number: PR_NUMBER) {
      reviewThreads(first: 100, after: $cursor) {
        pageInfo { hasNextPage endCursor }
        nodes {
          id
          isResolved
          comments(first: 1) {
            nodes { body path }
          }
        }
      }
    }
  }
}'
If
hasNextPage
is true, repeat with
-f cursor=ENDCURSOR
to get remaining threads.
Then resolve threads that have been addressed or are informational:
bash
gh api graphql -f query='
mutation {
  resolveReviewThread(input: {threadId: "THREAD_ID"}) {
    thread { isResolved }
  }
}'
Batch multiple resolutions into a single mutation using aliases (
t1
,
t2
, etc.).
处理完评论后,解决对应的评审线程。
首先,获取未解决的线程ID(若需要则分页——参考GraphQL参考文档):
bash
gh api graphql -f query='
query($cursor: String) {
  repository(owner: "OWNER", name: "REPO") {
    pullRequest(number: PR_NUMBER) {
      reviewThreads(first: 100, after: $cursor) {
        pageInfo { hasNextPage endCursor }
        nodes {
          id
          isResolved
          comments(first: 1) {
            nodes { body path }
          }
        }
      }
    }
  }
}'
如果
hasNextPage
为true,使用
-f cursor=ENDCURSOR
重复执行以获取剩余线程。
然后,解决已处理或属于信息类的线程:
bash
gh api graphql -f query='
mutation {
  resolveReviewThread(input: {threadId: "THREAD_ID"}) {
    thread { isResolved }
  }
}'
使用别名(
t1
t2
等)将多个解决操作批量处理为单个mutation。

9. Multiple PRs

9. 多个PR

If checking a chain of PRs, process them sequentially.
如果需要检查一系列PR,按顺序处理它们。

Output format

输出格式

Summarize:
  • PR title and current state
  • Status checks summary (passing/failing/pending)
  • Total issues found
  • Actionable items with descriptions
  • Items that can be ignored with reasons
  • Recommended next steps
汇总内容包括:
  • PR标题和当前状态
  • 状态检查汇总(通过/失败/待处理)
  • 发现的问题总数
  • 可操作项及描述
  • 可忽略项及原因
  • 建议的下一步操作