all-green

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

All Green: Get PR Ready to Merge

全绿状态:让PR达到可合并状态

Your goal is to get this PR to a mergeable state by addressing all blockers: review comments, merge conflicts, and failing checks.
你的目标是通过解决所有阻碍因素:评审意见、合并冲突和失败的检查,使该PR达到可合并状态。

Workflow

工作流程

Execute these steps in order:
按以下顺序执行步骤:

1. Identify the PR

1. 确定要处理的PR

First, determine which PR to work on:
bash
undefined
首先,确定要处理的PR:
bash
undefined

Get current branch and find associated PR

Get current branch and find associated PR

gh pr view --json number,title,url,headRefName,baseRefName,mergeable,mergeStateStatus,reviewDecision

If no PR exists for the current branch, inform the user and stop.
gh pr view --json number,title,url,headRefName,baseRefName,mergeable,mergeStateStatus,reviewDecision

如果当前分支没有对应的PR,请告知用户并停止操作。

2. Check PR Status

2. 检查PR状态

Gather the full picture of what needs to be addressed:
bash
undefined
全面收集需要处理的问题:
bash
undefined

Check for merge conflicts

Check for merge conflicts

gh pr view --json mergeable,mergeStateStatus
gh pr view --json mergeable,mergeStateStatus

Get CI check status

Get CI check status

gh pr checks
undefined
gh pr checks
undefined

3. Fetch and Address ALL Review Threads

3. 获取并处理所有评审线程

CRITICAL: You MUST fetch review threads using the GraphQL API and address every single unresolved one. This is NOT optional. Skipping this step is the #1 cause of PRs not being merge-ready.
Step 3a: Fetch all review threads (MANDATORY)
bash
gh api graphql -f query='
{
  repository(owner: "{owner}", name: "{repo}") {
    pullRequest(number: {pr_number}) {
      reviewThreads(first: 100) {
        nodes {
          id
          isResolved
          comments(first: 5) {
            nodes { body path line author { login } }
          }
        }
      }
    }
  }
}'
Filter to unresolved threads: look for
"isResolved": false
. If there are zero unresolved threads, you can skip to step 4. Otherwise, you MUST address every single one.
Step 3b: For EACH unresolved thread, do ALL of the following:
  1. Read the comment to understand what's being requested
  2. Read the relevant code in the file/line mentioned
  3. Make the requested change (or explain why not if you disagree)
  4. Reply to the thread explaining what you did:
    bash
    gh api graphql -f query='
    mutation {
      addPullRequestReviewThreadReply(input: {
        pullRequestReviewThreadId: "PRRT_xxx"
        body: "Fixed in commit abc123"
      }) {
        comment { id }
      }
    }'
  5. Resolve the thread — this is MANDATORY, do not skip:
    bash
    gh api graphql -f query='
    mutation {
      resolveReviewThread(input: {
        threadId: "PRRT_xxx"
      }) {
        thread { isResolved }
      }
    }'
Step 3c: Verify all threads are resolved (MANDATORY)
After addressing all threads, re-run the GraphQL query from step 3a and confirm zero unresolved threads remain. If any remain, go back and address them.
Tips:
  • Address comments in file order to avoid line number shifts
  • If a comment is unclear, ask the user for clarification
  • If you disagree with a suggestion, explain why in your reply and still resolve the thread
  • Always reply before resolving so reviewers can see what action was taken
  • Commit and push your fixes before replying/resolving so you can reference the commit hash
关键要求:你必须使用GraphQL API获取所有评审线程,并处理每一条未解决的线程。这不是可选步骤。跳过此步骤是PR无法达到可合并状态的首要原因。
步骤3a:获取所有评审线程(必填)
bash
gh api graphql -f query='
{
  repository(owner: "{owner}", name: "{repo}") {
    pullRequest(number: {pr_number}) {
      reviewThreads(first: 100) {
        nodes {
          id
          isResolved
          comments(first: 5) {
            nodes { body path line author { login } }
          }
        }
      }
    }
  }
}'
筛选出未解决的线程:查找
"isResolved": false
。如果没有未解决的线程,可以直接跳到步骤4。否则,必须处理每一条线程。
步骤3b:对每一条未解决的线程,执行以下所有操作:
  1. 阅读评论以理解要求
  2. 阅读相关代码(评论中提到的文件/行)
  3. 做出要求的更改(如果不同意,需说明原因)
  4. 回复线程说明你所做的操作:
    bash
    gh api graphql -f query='
    mutation {
      addPullRequestReviewThreadReply(input: {
        pullRequestReviewThreadId: "PRRT_xxx"
        body: "Fixed in commit abc123"
      }) {
        comment { id }
      }
    }'
  5. 标记线程为已解决 — 这是必填步骤,请勿跳过:
    bash
    gh api graphql -f query='
    mutation {
      resolveReviewThread(input: {
        threadId: "PRRT_xxx"
      }) {
        thread { isResolved }
      }
    }'
步骤3c:验证所有线程已解决(必填)
处理完所有线程后,重新运行步骤3a中的GraphQL查询,确认没有未解决的线程。如果仍有未解决的线程,请返回处理。
提示:
  • 按文件顺序处理评论,避免行号偏移
  • 如果评论不明确,请向用户请求澄清
  • 如果你不同意某个建议,请在回复中说明原因,然后仍标记线程为已解决
  • 回复后再标记为已解决,这样评审者可以看到你采取的操作
  • 在回复/标记解决之前,提交并推送你的修复,以便可以引用提交哈希

4. Resolve Merge Conflicts

4. 解决合并冲突

If the PR has merge conflicts:
bash
undefined
如果PR存在合并冲突:
bash
undefined

Fetch latest changes

Fetch latest changes

git fetch origin
git fetch origin

Get the base branch name from PR

Get the base branch name from PR

BASE_BRANCH=$(gh pr view --json baseRefName -q .baseRefName)
BASE_BRANCH=$(gh pr view --json baseRefName -q .baseRefName)

Rebase onto the base branch

Rebase onto the base branch

git rebase origin/$BASE_BRANCH

When resolving conflicts:
- **Read both versions** carefully to understand the intent
- **Preserve both changes** when they're independent
- **Choose the correct version** when they conflict
- **Run type checking** after resolving to catch issues

```bash
git rebase origin/$BASE_BRANCH

解决冲突时:
- **仔细阅读两个版本**以理解意图
- **当更改独立时,保留双方的修改**
- **当更改冲突时,选择正确的版本**
- **解决冲突后运行类型检查**以发现问题

```bash

After resolving conflicts

After resolving conflicts

git add <resolved-files> git rebase --continue
git add <resolved-files> git rebase --continue

Verify types still check

Verify types still check

npm run tsgo:check
undefined
npm run tsgo:check
undefined

5. Fix Failing Checks

5. 修复失败的检查

For each failing check:
bash
undefined
针对每一项失败的检查:
bash
undefined

Get detailed check failure information

Get detailed check failure information

gh pr checks --json name,state,conclusion,detailsUrl

Common fixes:

**Type errors:**
```bash
npm run tsgo:check  # Identify the errors
gh pr checks --json name,state,conclusion,detailsUrl

常见修复方法:

**类型错误:**
```bash
npm run tsgo:check  # Identify the errors

Fix each type error in the reported files

Fix each type error in the reported files


**Lint errors:**
```bash
npm run lint        # See lint issues
npm run lint:fix    # Auto-fix what's possible

**Lint错误:**
```bash
npm run lint        # See lint issues
npm run lint:fix    # Auto-fix what's possible

Manually fix remaining issues

Manually fix remaining issues


**Test failures:**
```bash
npm test            # Run tests to see failures

**测试失败:**
```bash
npm test            # Run tests to see failures

Read failing test files and fix the issues

Read failing test files and fix the issues


**Build failures:**
- Check for missing imports
- Check for syntax errors
- Verify all dependencies are installed

**构建失败:**
- 检查是否缺少导入
- 检查是否存在语法错误
- 验证所有依赖项已安装

6. Push and Wait for Checks

6. 推送并等待检查完成

After all fixes:
bash
undefined
完成所有修复后:
bash
undefined

If you rebased, force push is required

If you rebased, force push is required

git push --force-with-lease
git push --force-with-lease

If you only added commits

If you only added commits

git push

Then **wait for checks to complete** using the blocking watch command:

```bash
git push

然后使用阻塞式监控命令**等待检查完成**:

```bash

Block until checks finish, exit immediately on first failure

Block until checks finish, exit immediately on first failure

gh pr checks --watch --fail-fast

This command:
- Blocks until all checks complete (no polling/tokens wasted)
- Exits immediately with status 1 if any check fails (fail-fast)
- Exits with status 0 if all checks pass
- Exits with status 8 if checks are still pending (shouldn't happen with --watch)
gh pr checks --watch --fail-fast

此命令:
- 阻塞直到所有检查完成(无需轮询/浪费令牌)
- 如果任何检查失败,立即以状态1退出(快速失败)
- 如果所有检查通过,以状态0退出
- 如果检查仍在进行中,以状态8退出(使用--watch时不应发生)

7. Handle Check Failures

7. 处理检查失败

If
gh pr checks --watch --fail-fast
exits with a failure:
bash
undefined
如果
gh pr checks --watch --fail-fast
以失败状态退出:
bash
undefined

See which check failed and get the details URL

See which check failed and get the details URL

gh pr checks --json name,state,conclusion,detailsUrl
gh pr checks --json name,state,conclusion,detailsUrl

View the failed run logs directly

View the failed run logs directly

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

Fix the issue, commit, push, and run `gh pr checks --watch --fail-fast` again.
gh run view <run-id> --log-failed

修复问题,提交,推送,然后再次运行`gh pr checks --watch --fail-fast`。

8. Verify Merge Readiness

8. 验证可合并状态

Once checks pass:
bash
gh pr view --json mergeable,mergeStateStatus,reviewDecision
检查通过后:
bash
gh pr view --json mergeable,mergeStateStatus,reviewDecision

Important Notes

重要说明

  • EVERY unresolved review thread must be addressed and resolved — this is the most important part of getting a PR to green. Do not skip this step or treat it as optional. Always verify with a follow-up GraphQL query that zero unresolved threads remain.
  • Ask before force-pushing if there might be other collaborators on the branch
  • Run type checking frequently to catch issues early
  • Commit logically - group related fixes together
  • If checks keep failing after fixes, read the CI logs carefully:
    bash
    gh run view <run-id> --log-failed
  • 每一条未解决的评审线程都必须被处理并标记为已解决 — 这是让PR变为全绿状态最重要的部分。请勿跳过此步骤或将其视为可选操作。始终通过后续的GraphQL查询验证是否存在未解决的线程。
  • 如果分支上可能有其他协作者,强制推送前请询问
  • 频繁运行类型检查以尽早发现问题
  • 合理提交 - 将相关修复分组提交
  • 如果修复后检查仍持续失败,请仔细阅读CI日志:
    bash
    gh run view <run-id> --log-failed

Example Session

示例会话

bash
undefined
bash
undefined

1. See what we're dealing with

1. See what we're dealing with

gh pr view --json number,title,mergeable,mergeStateStatus,reviewDecision gh pr checks
gh pr view --json number,title,mergeable,mergeStateStatus,reviewDecision gh pr checks

2. MANDATORY: Fetch ALL review threads and find unresolved ones

2. MANDATORY: Fetch ALL review threads and find unresolved ones

gh api graphql -f query='{ repository(owner: "OWNER", name: "REPO") { pullRequest(number: PR_NUM) { reviewThreads(first: 100) { nodes { id isResolved comments(first: 5) { nodes { body path line author { login } } } } } } } }'
gh api graphql -f query='{ repository(owner: "OWNER", name: "REPO") { pullRequest(number: PR_NUM) { reviewThreads(first: 100) { nodes { id isResolved comments(first: 5) { nodes { body path line author { login } } } } } } } }'

3. Address each unresolved thread: read code, make fix, commit

3. Address each unresolved thread: read code, make fix, commit

4. Push fixes

4. Push fixes

git push
git push

5. Reply to and resolve EVERY addressed thread

5. Reply to and resolve EVERY addressed thread

gh api graphql -f query='mutation { addPullRequestReviewThreadReply(input: { pullRequestReviewThreadId: "PRRT_xxx", body: "Fixed in abc123 — added encodeURIComponent" }) { comment { id } } }' gh api graphql -f query='mutation { resolveReviewThread(input: { threadId: "PRRT_xxx" }) { thread { isResolved } } }'
gh api graphql -f query='mutation { addPullRequestReviewThreadReply(input: { pullRequestReviewThreadId: "PRRT_xxx", body: "Fixed in abc123 — added encodeURIComponent" }) { comment { id } } }' gh api graphql -f query='mutation { resolveReviewThread(input: { threadId: "PRRT_xxx" }) { thread { isResolved } } }'

6. VERIFY: Re-fetch threads and confirm zero unresolved remain

6. VERIFY: Re-fetch threads and confirm zero unresolved remain

(Re-run the GraphQL query from step 2, filter for isResolved: false)

(Re-run the GraphQL query from step 2, filter for isResolved: false)

7. If there are merge conflicts, rebase

7. If there are merge conflicts, rebase

git fetch origin git rebase origin/main
git fetch origin git rebase origin/main

... resolve conflicts ...

... resolve conflicts ...

git add . git rebase --continue
git add . git rebase --continue

8. Fix any failing checks

8. Fix any failing checks

npm run tsgo:check npm run lint:fix npm test
npm run tsgo:check npm run lint:fix npm test

9. Push and wait for checks (blocks until complete, fails fast)

9. Push and wait for checks (blocks until complete, fails fast)

git push --force-with-lease gh pr checks --watch --fail-fast
git push --force-with-lease gh pr checks --watch --fail-fast

10. If checks failed, fix and repeat. Once green:

10. If checks failed, fix and repeat. Once green:

gh pr view --json mergeable,mergeStateStatus,reviewDecision
undefined
gh pr view --json mergeable,mergeStateStatus,reviewDecision
undefined