pr-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub PR Review Skill

GitHub PR Review Skill

Overview

概述

This skill automatically processes unresolved GitHub Pull Request review discussions by analyzing the code context, validating feedback, and taking appropriate actions. It intelligently categorizes feedback as valid, invalid, or already addressed, then creates action plans or posts clarifying responses accordingly.
该Skill会通过分析代码上下文、验证反馈并采取相应操作,自动处理未解决的GitHub Pull Request评审讨论。它能智能地将反馈分类为有效、无效或已解决,然后据此创建行动计划或发布澄清回复。

Supported Actions

支持的操作

Action TypeWhen UsedOutcome
Create TodoValid feedback needing fixesAdds task to todo list
Reply & ResolveInvalid or misunderstood feedbackPosts clarifying comment, resolves thread
Confirm & ResolveAlready fixed feedbackPosts confirmation, resolves thread
EscalateAmbiguous or complex feedbackAsks user for guidance
操作类型使用场景结果
创建待办事项需要修复的有效反馈将任务添加到待办列表
回复并解决无效或被误解的反馈发布澄清评论,解决讨论线程
确认并解决已修复的反馈发布确认信息,解决讨论线程
升级处理模糊或复杂的反馈向用户寻求指导

Discussion Classification

讨论分类

Valid Feedback

有效反馈

Legitimate issues that require code changes:
  • Missing error handling
  • Type safety concerns
  • Performance problems
  • Security vulnerabilities
  • Logic errors
需要修改代码的合理问题:
  • 缺少错误处理
  • 类型安全性问题
  • 性能问题
  • 安全漏洞
  • 逻辑错误

Invalid Feedback

无效反馈

Misunderstandings or incorrect observations:
  • Code already handles the mentioned case
  • Reviewer misread the implementation
  • Feedback based on outdated context
  • Incorrect assumptions
误解或错误的观察:
  • 代码已处理提及的情况
  • 评审者误读了实现
  • 基于过时上下文的反馈
  • 错误的假设

Already Addressed

已解决

Feedback that has been fixed since review:
  • Changes made in recent commits
  • Fixed in different files
  • Resolved through refactoring
评审后已修复的反馈:
  • 在最近的提交中已修改
  • 在其他文件中已修复
  • 通过重构已解决

Workflow

工作流程

1. Verify GitHub CLI Installation

1. 验证GitHub CLI安装

Check if gh CLI is available:
bash
gh --version
Expected output:
  • Success:
    gh version X.Y.Z (YYYY-MM-DD)
  • Failure: Command not found error
If not installed, display installation guide:
GitHub CLI (gh) is not installed.

Installation:
  macOS:          brew install gh
  Ubuntu/Debian:  sudo apt install gh
  Windows:        winget install GitHub.cli
  Linux (other):  See https://github.com/cli/cli#installation

After installation, authenticate:
  gh auth login
Verify authentication:
bash
gh auth status
If not authenticated:
Please authenticate with GitHub:
  gh auth login

Follow the prompts to complete authentication.
检查gh CLI是否可用:
bash
gh --version
预期输出:
  • 成功:
    gh version X.Y.Z (YYYY-MM-DD)
  • 失败:命令未找到错误
如果未安装,显示安装指南:
GitHub CLI (gh) 未安装。

安装方式:
  macOS:          brew install gh
  Ubuntu/Debian:  sudo apt install gh
  Windows:        winget install GitHub.cli
  Linux (其他):  参见 https://github.com/cli/cli#installation

安装后,进行身份验证:
  gh auth login
验证身份验证状态:
bash
gh auth status
如果未验证:
请使用GitHub进行身份验证:
  gh auth login

按照提示完成身份验证。

2. Parse PR URL

2. 解析PR URL

Extract repository and PR information from argument:
URL format:
https://github.com/{owner}/{repo}/pull/{number}
Extraction logic:
bash
url="$ARGUMENTS"
owner=$(echo "$url" | sed -n 's#.*/github.com/\([^/]*\)/.*#\1#p')
repo=$(echo "$url" | sed -n 's#.*/github.com/[^/]*/\([^/]*\)/.*#\1#p')
pr_number=$(echo "$url" | sed -n 's#.*/pull/\([0-9]*\).*#\1#p')
Example:
Input:  https://github.com/anthropics/claude-code/pull/123
Output: owner=anthropics, repo=claude-code, pr_number=123
Validation:
  • Ensure all three values are non-empty
  • Verify PR number is numeric
  • Confirm URL matches expected pattern
If URL invalid:
Error: Invalid GitHub PR URL

Expected format: https://github.com/OWNER/REPO/pull/NUMBER
Example: https://github.com/anthropics/claude-code/pull/123
从参数中提取仓库和PR信息:
URL格式:
https://github.com/{owner}/{repo}/pull/{number}
提取逻辑:
bash
url="$ARGUMENTS"
owner=$(echo "$url" | sed -n 's#.*/github.com/\([^/]*\)/.*#\1#p')
repo=$(echo "$url" | sed -n 's#.*/github.com/[^/]*/\([^/]*\)/.*#\1#p')
pr_number=$(echo "$url" | sed -n 's#.*/pull/\([0-9]*\).*#\1#p')
示例:
输入:  https://github.com/anthropics/claude-code/pull/123
输出: owner=anthropics, repo=claude-code, pr_number=123
验证:
  • 确保三个值均非空
  • 验证PR编号为数字
  • 确认URL符合预期格式
如果URL无效:
错误:无效的GitHub PR URL

预期格式:https://github.com/OWNER/REPO/pull/NUMBER
示例:https://github.com/anthropics/claude-code/pull/123

3. Fetch Unresolved Discussions

3. 获取未解决的讨论

Query GitHub GraphQL API for review threads:
bash
gh api graphql -f query='
  query($owner: String!, $repo: String!, $pr: Int!) {
    repository(owner: $owner, name: $repo) {
      pullRequest(number: $pr) {
        title
        author { login }
        reviewThreads(first: 100) {
          nodes {
            id
            isResolved
            isOutdated
            path
            line
            comments(first: 10) {
              nodes {
                id
                body
                author { login }
                createdAt
              }
            }
          }
        }
      }
    }
  }
' -f owner="$owner" -f repo="$repo" -F pr="$pr_number"
Response structure:
json
{
  "data": {
    "repository": {
      "pullRequest": {
        "reviewThreads": {
          "nodes": [
            {
              "id": "PRRT_...",
              "isResolved": false,
              "isOutdated": false,
              "path": "src/auth.ts",
              "line": 45,
              "comments": {
                "nodes": [
                  {
                    "body": "This needs null checking",
                    "author": {"login": "reviewer"},
                    "createdAt": "2024-01-01T12:00:00Z"
                  }
                ]
              }
            }
          ]
        }
      }
    }
  }
}
Filter for unresolved threads:
  • Extract threads where
    isResolved: false
  • Optionally include
    isOutdated: true
    threads (may be relevant)
  • Store thread ID, path, line, and all comments
If no unresolved discussions:
✓ All review discussions have been resolved

PR: [PR Title]
Status: No pending feedback
查询GitHub GraphQL API获取评审线程:
bash
gh api graphql -f query='
  query($owner: String!, $repo: String!, $pr: Int!) {
    repository(owner: $owner, name: $repo) {
      pullRequest(number: $pr) {
        title
        author { login }
        reviewThreads(first: 100) {
          nodes {
            id
            isResolved
            isOutdated
            path
            line
            comments(first: 10) {
              nodes {
                id
                body
                author { login }
                createdAt
              }
            }
          }
        }
      }
    }
  }
' -f owner="$owner" -f repo="$repo" -F pr="$pr_number"
响应结构:
json
{
  "data": {
    "repository": {
      "pullRequest": {
        "reviewThreads": {
          "nodes": [
            {
              "id": "PRRT_...",
              "isResolved": false,
              "isOutdated": false,
              "path": "src/auth.ts",
              "line": 45,
              "comments": {
                "nodes": [
                  {
                    "body": "This needs null checking",
                    "author": {"login": "reviewer"},
                    "createdAt": "2024-01-01T12:00:00Z"
                  }
                ]
              }
            }
          ]
        }
      }
    }
  }
}
筛选未解决的线程:
  • 提取
    isResolved: false
    的线程
  • 可选择包含
    isOutdated: true
    的线程(可能相关)
  • 存储线程ID、路径、行号和所有评论
如果没有未解决的讨论:
✓ 所有评审讨论均已解决

PR: [PR标题]
状态:无待处理反馈

4. Analyze Each Discussion

4. 分析每个讨论

For each unresolved thread, perform comprehensive analysis:
对每个未解决的线程进行全面分析:

4.1 Read Local Code

4.1 读取本地代码

Fetch the file at the specified path:
bash
undefined
获取指定路径的文件:
bash
undefined

Read the file with context around the line

读取文件并包含行号周围的上下文

Read file_path="$path"

**Extract relevant section:**
- Focus on the specific line mentioned
- Include 10 lines before and after for context
- Identify function/class scope
Read file_path="$path"

**提取相关部分:**
- 重点关注提及的特定行
- 包含前后10行作为上下文
- 识别函数/类范围

4.2 Fetch PR Diff

4.2 获取PR差异

Get the complete PR diff:
bash
gh pr diff "$pr_number" -R "$owner/$repo"
Parse diff for the specific file:
  • Locate changes to the file mentioned in comment
  • Identify if the line was added, modified, or is context
  • Check if subsequent commits modified this area
获取完整的PR差异:
bash
gh pr diff "$pr_number" -R "$owner/$repo"
解析特定文件的差异:
  • 定位评论中提到的文件的变更
  • 识别该行是新增、修改还是上下文
  • 检查后续提交是否修改了该区域

4.3 Review Comment Thread

4.3 评审评论线程

Analyze all comments in the thread:
  • First comment: Original reviewer feedback
  • Subsequent comments: Author responses and discussion
  • Extract key concerns and questions
  • Identify if conversation reached conclusion
分析线程中的所有评论:
  • 第一条评论:原始评审者反馈
  • 后续评论:作者回复和讨论
  • 提取关键关注点和问题
  • 识别对话是否已达成结论

4.4 Compare States

4.4 对比状态

Determine the current state:
  1. Has code changed since review?
    • Check git log for commits after review comment timestamp
    • Compare current code to PR diff
  2. Does current code address the concern?
    • Valid feedback: Code still has the issue
    • Invalid feedback: Code already handles it
    • Already addressed: Fixed in later commits
  3. Is feedback contextually correct?
    • Reviewer may have missed related code
    • Check imports and dependencies
    • Verify assumptions in the comment
确定当前状态:
  1. 评审后代码是否有变更?
    • 检查git日志中评审评论时间戳之后的提交
    • 对比当前代码与PR差异
  2. 当前代码是否解决了该问题?
    • 有效反馈:代码仍存在该问题
    • 无效反馈:代码已处理该问题
    • 已解决:在后续提交中已修复
  3. 反馈的上下文是否正确?
    • 评审者可能遗漏了相关代码
    • 检查导入和依赖
    • 验证评论中的假设

5. Categorize and Process

5. 分类并处理

Type A: Valid Feedback (Needs Fix)

类型A:有效反馈(需要修复)

Identification:
  • Issue exists in current code
  • Feedback is technically correct
  • Change would improve code quality
Action:
bash
undefined
识别条件:
  • 当前代码存在该问题
  • 反馈在技术上正确
  • 修改可提升代码质量
操作:
bash
undefined

Add to todo list using TodoWrite

使用TodoWrite添加到待办列表

TodoWrite:
  • content: "Fix [issue] in [file]:[line]"
  • status: "pending"

**Example:**
Discussion: "Missing null check for user.profile" Current code: No null check present Category: Valid Feedback
Action: Added todo "Add null check for user.profile in auth.ts:45"
undefined
TodoWrite:
  • content: "修复 [文件]:[行号] 中的 [问题]"
  • status: "pending"

**示例:**
讨论:"Missing null check for user.profile" 当前代码:未存在空值检查 分类:有效反馈
操作:添加待办事项 "在auth.ts:45中添加user.profile的空值检查"
undefined

Type B: Invalid Feedback (Misunderstanding)

类型B:无效反馈(误解)

Identification:
  • Code already handles the concern
  • Reviewer misunderstood implementation
  • Feedback based on incorrect assumption
Action:
bash
undefined
识别条件:
  • 代码已处理该问题
  • 评审者误解了实现
  • 反馈基于错误的假设
操作:
bash
undefined

Post clarifying comment

发布澄清评论

gh api graphql -f query=' mutation($threadId: ID!, $body: String!) { addPullRequestReviewThreadReply(input: { pullRequestReviewThreadId: $threadId body: $body }) { comment { id } } } ' -f threadId="$thread_id" -f body="[polite clarification]"
gh api graphql -f query=' mutation($threadId: ID!, $body: String!) { addPullRequestReviewThreadReply(input: { pullRequestReviewThreadId: $threadId body: $body }) { comment { id } } } ' -f threadId="$thread_id" -f body="[礼貌的澄清内容]"

Resolve the thread

解决线程

gh api graphql -f query=' mutation($threadId: ID!) { resolveReviewThread(input: {threadId: $threadId}) { thread { isResolved } } } ' -f threadId="$thread_id"

**Comment template:**
Thank you for the feedback! This is actually already handled:
[Explanation with code reference]
The [specific mechanism] ensures [desired behavior].
Reference: [file]:[line]

**Example:**
Discussion: "Variable 'token' is unused" Current code: Variable used on line 67 Category: Invalid Feedback
Reply: "Thank you for checking! The 'token' variable is actually used on line 67 in the authentication middleware. Here's the usage:
    ```typescript
    if (token) {
      return validateToken(token);
    }
    ```"
Action: Resolved thread
undefined
gh api graphql -f query=' mutation($threadId: ID!) { resolveReviewThread(input: {threadId: $threadId}) { thread { isResolved } } } ' -f threadId="$thread_id"

**评论模板:**
感谢您的反馈!实际上这个问题已经得到处理:
[带有代码引用的解释]
[特定机制] 确保了[预期行为]。
引用:[文件]:[行号]

**示例:**
讨论:"Variable 'token' is unused" 当前代码:变量在第67行被使用 分类:无效反馈
回复:"感谢您的检查!'token'变量实际上在身份验证中间件的第67行被使用。以下是使用代码:
    ```typescript
    if (token) {
      return validateToken(token);
    }
    ```"
操作:解决线程
undefined

Type C: Already Addressed

类型C:已解决

Identification:
  • Issue existed at review time
  • Fixed in subsequent commits
  • Current code is correct
Action:
bash
undefined
识别条件:
  • 评审时存在该问题
  • 在后续提交中已修复
  • 当前代码正确
操作:
bash
undefined

Post confirmation comment

发布确认评论

gh api graphql -f query='[same mutation as Type B]'
-f threadId="$thread_id"
-f body="This has been addressed in commit [hash]. [Brief explanation]"
gh api graphql -f query='[与类型B相同的mutation]'
-f threadId="$thread_id"
-f body="该问题已在提交[哈希值]中解决。[简要说明]"

Resolve thread

解决线程

gh api graphql -f query='[same resolve mutation]' -f threadId="$thread_id"

**Comment template:**
This has been addressed in commit [short-hash].
Changes made: [Brief summary of the fix]
Current implementation: [Code snippet if helpful]

**Example:**
Discussion: "Add TypeScript types for User interface" Current code: User interface fully typed Category: Already Addressed
Reply: "This has been addressed in commit abc123f. Added comprehensive TypeScript types for the User interface including optional fields." Action: Resolved thread
undefined
gh api graphql -f query='[与类型B相同的解决mutation]' -f threadId="$thread_id"

**评论模板:**
该问题已在提交[短哈希值]中解决。
所做修改: [修复的简要总结]
当前实现: [如有帮助,可附上代码片段]

**示例:**
讨论:"Missing return type annotation" 当前代码:User接口已完全添加类型 分类:已解决
回复:"该问题已在提交a1b2c3d中解决。为所有导出函数添加了返回类型注释,包括此函数。
当前实现:
typescript
function calculate(): number {
  return 42;
}
```"

操作:解决线程

Type D: Ambiguous or Complex

类型D:模糊或复杂

Identification:
  • Feedback requires design decision
  • Multiple valid approaches exist
  • User input needed for direction
Action:
bash
undefined
识别条件:
  • 反馈需要设计决策
  • 存在多种有效方案
  • 需要用户输入来确定方向
操作:
bash
undefined

Ask user for guidance using AskUserQuestion

使用AskUserQuestion向用户寻求指导

AskUserQuestion: question: "[Reviewer] suggests [approach]. How would you like to proceed?" options: - Implement suggested approach - Explain current approach to reviewer - Discuss alternative solution
undefined
AskUserQuestion: question: "[评审者] 建议[方案]。您希望如何处理?" options: - 实施建议的方案 - 向评审者解释当前方案 - 讨论替代解决方案
undefined

6. Generate Summary Report

6. 生成总结报告

After processing all discussions, create summary:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
PR Review Processing Complete
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

PR: [PR Title] (#[number])
Repository: [owner]/[repo]

Summary:
  Total discussions:    [X]
  Valid feedback:       [Y] → Added to todo list
  Invalid feedback:     [Z] → Clarified and resolved
  Already addressed:    [W] → Confirmed and resolved
  Escalated:           [N] → Requires user input

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Action Items Created:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. [file]:[line] - [description]
2. [file]:[line] - [description]

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Resolved Discussions:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✓ [file]:[line] - [reason for resolution]
✓ [file]:[line] - [reason for resolution]

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
处理完所有讨论后,创建总结:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
PR评审处理完成
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

PR: [PR标题] (#[编号])
仓库: [owner]/[repo]

总结:
  总讨论数:    [X]
  有效反馈:       [Y] → 已添加到待办列表
  无效反馈:     [Z] → 已澄清并解决
  已解决:    [W] → 已确认并解决
  升级处理:           [N] → 需要用户输入

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
创建的操作项:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. [文件]:[行号] - [描述]
2. [文件]:[行号] - [描述]

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
已解决的讨论:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✓ [文件]:[行号] - [解决原因]
✓ [文件]:[行号] - [解决原因]

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

7. 반복 처리 루프

7. 循环处理流程

수정사항(Valid Feedback)이 있는 경우 모든 discussion이 해결될 때까지 다음 사이클을 반복합니다:
如果存在需要修改的反馈(Valid Feedback),则重复以下流程,直到所有讨论都得到解决:

7.1 코드 수정 및 Push

7.1 代码修改并推送

Todo 항목에 따라 코드 수정 후 push:
bash
undefined
根据待办事项修改代码后推送:
bash
undefined

변경사항 커밋

提交变更

git add . git commit -m "fix: address PR review feedback"
git add . git commit -m "fix: address PR review feedback"

Push

推送

git push
undefined
git push
undefined

7.2 CI Check 대기

7.2 等待CI检查

PR의 모든 check가 완료될 때까지 대기:
bash
undefined
等待PR的所有检查完成:
bash
undefined

Check 상태 모니터링 (완료될 때까지 polling)

监控检查状态(轮询直到完成)

gh pr checks "$pr_number" -R "$owner/$repo" --watch

**Check 상태 확인:**
```bash
gh pr checks "$pr_number" -R "$owner/$repo"
예상 출력:
Some checks are still pending
0 failing, 1 pending, 0 passing, and 0 skipped checks

build   In progress  https://github.com/...
Check 완료 대기 로직:
  • --watch
    플래그로 실시간 모니터링
  • 모든 check가 pass/fail/skipped 상태가 될 때까지 대기
  • Check 실패 시 사용자에게 알림 후 계속 진행
gh pr checks "$pr_number" -R "$owner/$repo" --watch

**检查状态:**
```bash
gh pr checks "$pr_number" -R "$owner/$repo"
预期输出:
部分检查仍在进行中
0个失败,1个待处理,0个通过,0个跳过的检查

build   进行中  https://github.com/...
等待检查完成的逻辑:
  • 使用
    --watch
    标志实时监控
  • 等待所有检查变为通过/失败/跳过状态
  • 检查失败时通知用户后继续进行

7.3 새로운 Discussion 확인

7.3 检查新的讨论

Check 완료 후 새로운 unresolved discussion 조회:
bash
undefined
检查完成后查询新的未解决讨论:
bash
undefined

3단계의 GraphQL 쿼리 재실행

重新执行第3步的GraphQL查询

gh api graphql -f query=' query($owner: String!, $repo: String!, $pr: Int!) { repository(owner: $owner, name: $repo) { pullRequest(number: $pr) { reviewThreads(first: 100) { nodes { id isResolved isOutdated path line comments(first: 10) { nodes { id body author { login } createdAt } } } } } } } ' -f owner="$owner" -f repo="$repo" -F pr="$pr_number"

**새 discussion 발견 시:**
- 4단계(분석)부터 다시 시작
- 새로운 discussion 처리
gh api graphql -f query=' query($owner: String!, $repo: String!, $pr: Int!) { repository(owner: $owner, name: $repo) { pullRequest(number: $pr) { reviewThreads(first: 100) { nodes { id isResolved isOutdated path line comments(first: 10) { nodes { id body author { login } createdAt } } } } } } } ' -f owner="$owner" -f repo="$repo" -F pr="$pr_number"

**发现新讨论时:**
- 从第4步(分析)重新开始
- 处理新讨论

7.4 종료 조건

7.4 终止条件

루프 종료 조건:
  • Unresolved discussion이 0개
  • 모든 CI check 통과
최종 완료 메시지:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✓ PR Review 처리 완료
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

PR: [PR Title] (#[number])
Repository: [owner]/[repo]

처리 사이클: [N]회
총 처리 discussion: [X]개
CI Check: ✓ 모두 통과

모든 review feedback이 처리되었습니다.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
循环终止条件:
  • 未解决讨论数为0
  • 所有CI检查通过
最终完成消息:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✓ PR评审处理完成
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

PR: [PR标题] (#[编号])
仓库: [owner]/[repo]

处理周期: [N]次
总处理讨论数: [X]个
CI检查: ✓ 全部通过

所有评审反馈均已处理完毕。
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

7.5 루프 흐름도

7.5 循环流程图

┌─────────────────────────────────────────────────────────┐
│                    시작                                  │
└────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│          Unresolved discussion 조회                      │
└────────────────────────┬────────────────────────────────┘
              ┌─────────────────────┐
              │ discussion 있음?    │
              └──────────┬──────────┘
                   │           │
                  Yes          No
                   │           │
                   ▼           ▼
┌──────────────────────┐  ┌─────────────────────────┐
│ 분석 및 분류 (4단계)  │  │     ✓ 처리 완료         │
└──────────┬───────────┘  │     루프 종료           │
           ▼              └─────────────────────────┘
┌──────────────────────┐
│ 처리 및 응답 (5단계)  │
│ - Valid: 수정        │
│ - Invalid: resolve   │
│ - Addressed: resolve │
└──────────┬───────────┘
     ┌───────────┐
     │ 수정 있음? │
     └─────┬─────┘
       Yes │
┌──────────────────────┐
│ git commit && push   │
└──────────┬───────────┘
┌──────────────────────┐
│ CI Check 대기        │
│ gh pr checks --watch │
└──────────┬───────────┘
           │ (처음으로 돌아감)
           └────────────────────────────────────────┐
              ┌─────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│          Unresolved discussion 재조회                    │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│                    开始                                  │
└────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│          查询未解决讨论                      │
└────────────────────────┬────────────────────────────────┘
              ┌─────────────────────┐
              │ 存在讨论吗?    │
              └──────────┬──────────┘
                   │           │
                  是          否
                   │           │
                   ▼           ▼
┌──────────────────────┐  ┌─────────────────────────┐
│ 分析及分类(第4步)  │  │     ✓ 处理完成         │
└──────────┬───────────┘  │     循环终止           │
           ▼              └─────────────────────────┘
┌──────────────────────┐
│ 处理及响应(第5步)  │
│ - 有效:修改        │
│ - 无效:解决   │
│ - 已解决:解决 │
└──────────┬───────────┘
     ┌───────────┐
     │ 存在修改吗? │
     └─────┬─────┘
       是 │
┌──────────────────────┐
│ git commit && push   │
└──────────┬───────────┘
┌──────────────────────┐
│ 等待CI检查        │
│ gh pr checks --watch │
└──────────┬───────────┘
           │ (返回开始)
           └────────────────────────────────────────┐
              ┌─────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│          重新查询未解决讨论                    │
└─────────────────────────────────────────────────────────┘

Examples

示例

Example 1: Valid Null Check Feedback

示例1:有效的空值检查反馈

Review comment:
src/auth.ts:45
"This function should handle null user profiles"
Analysis:
bash
undefined
评审评论:
src/auth.ts:45
"This function should handle null user profiles"
分析:
bash
undefined

Read file

读取文件

Read src/auth.ts
Read src/auth.ts

Check lines 35-55

检查35-55行

function getProfile(user) { return user.profile.name; // Line 45 - no null check }

**Outcome:**
Category: Valid Feedback Action: Added todo "Add null check for user.profile in auth.ts:45"
undefined
function getProfile(user) { return user.profile.name; // 第45行 - 无空值检查 }

**结果:**
分类:有效反馈 操作:添加待办事项 "在auth.ts:45中添加user.profile的空值检查"
undefined

Example 2: Misunderstood Variable Usage

示例2:被误解的变量使用

Review comment:
src/api.ts:120
"Variable 'cache' is declared but never used"
Analysis:
bash
undefined
评审评论:
src/api.ts:120
"Variable 'cache' is declared but never used"
分析:
bash
undefined

Read file

读取文件

Read src/api.ts
Read src/api.ts

Check lines 110-140

检查110-140行

const cache = new Map(); // Line 120
function getData(key) { if (cache.has(key)) { // Line 130 - using cache return cache.get(key); } // ... }

**Outcome:**
Category: Invalid Feedback
Reply posted: "Thank you for reviewing! The 'cache' variable is actually used in the getData function on lines 130-132 for memoization. Here's the usage:
typescript
if (cache.has(key)) {
  return cache.get(key);
}
The cache improves performance by storing previously fetched data."
Action: Resolved thread
undefined
const cache = new Map(); // 第120行
function getData(key) { if (cache.has(key)) { // 第130行 - 使用cache return cache.get(key); } // ... }

**结果:**
分类:无效反馈
发布的回复: "感谢您的评审!'cache'变量实际上在getData函数的第130-132行用于记忆化。以下是使用代码:
typescript
if (cache.has(key)) {
  return cache.get(key);
}
缓存通过存储已获取的数据来提升性能。" 操作:解决线程
undefined

Example 3: Already Fixed Type Issue

示例3:已修复的类型问题

Review comment:
src/types.ts:15
"Missing return type annotation"
Analysis:
bash
undefined
评审评论:
src/types.ts:15
"Missing return type annotation"
分析:
bash
undefined

Check current code

检查当前代码

Read src/types.ts
Read src/types.ts

Line 15 now has type annotation

第15行现在已添加类型注释

function calculate(): number { // Line 15 - type added return 42; }
function calculate(): number { // 第15行 - 添加了类型 return 42; }

Check git log

检查git日志

git log --oneline --since="[review date]" src/types.ts
git log --oneline --since="[评审日期]" src/types.ts

Shows: "a1b2c3d feat(types): add return type annotations"

显示:"a1b2c3d feat(types): add return type annotations"


**Outcome:**
Category: Already Addressed
Reply posted: "This has been addressed in commit a1b2c3d. Added return type annotations to all exported functions including this one.
Current implementation:
typescript
function calculate(): number {
  return 42;
}
```"

Action: Resolved thread

**结果:**
分类:已解决
回复:"该问题已在提交a1b2c3d中解决。为所有导出函数添加了返回类型注释,包括此函数。
当前实现:
typescript
function calculate(): number {
  return 42;
}
```"

操作:解决线程

Technical Requirements

技术要求

Required Tools

必备工具

ToolPurposeInstallationCheck Command
GitHub CLIAPI access
brew install gh
gh --version
GitLocal repositoryBuilt-in or package manager
git --version
jqJSON parsing
brew install jq
jq --version
工具用途安装方式检查命令
GitHub CLIAPI访问
brew install gh
gh --version
Git本地仓库内置或包管理器
git --version
jqJSON解析
brew install jq
jq --version

API Requirements

API要求

  • GitHub API: GraphQL endpoint access
  • Authentication: Valid GitHub token with repo scope
  • Rate limits: ~5000 requests/hour (authenticated)
  • Permissions: Read access to repository, write access to PR comments
  • GitHub API: GraphQL端点访问权限
  • 身份验证: 有效的GitHub令牌,具有repo权限
  • 速率限制: 约5000次请求/小时(已验证)
  • 权限: 仓库的读取权限,PR评论的写入权限

Minimum Versions

最低版本

  • gh CLI: 2.0.0 or higher
  • Git: 2.0 or higher
  • jq: 1.6 or higher
  • gh CLI: 2.0.0或更高
  • Git: 2.0或更高
  • jq: 1.6或更高

Best Practices

最佳实践

  1. Always read local code before making judgments
  2. Be polite and professional in all responses
  3. Provide code references to support clarifications
  4. Resolve threads only after posting comments
  5. Group related todos for efficiency
  6. Include commit hashes when mentioning fixes
  7. Ask for user input when uncertain
  8. Check git history to understand recent changes
  1. 始终先读取本地代码再做出判断
  2. 所有回复保持礼貌和专业
  3. 提供代码引用以支持澄清内容
  4. 发布评论后再解决线程
  5. 将相关待办事项分组以提高效率
  6. 提及修复时包含提交哈希值
  7. 不确定时向用户寻求输入
  8. 检查git历史以了解最近的变更

Limitations

局限性

  1. Local context only: Analysis based on local repository state
  2. 100 discussions max: GraphQL query limited to first 100 threads
  3. 10 comments per thread: Comment fetch limited to first 10
  4. No file history: Cannot analyze full file evolution
  5. Requires authentication: Must have GitHub access token
  6. Rate limiting: May hit API limits on large PRs
  1. 仅本地上下文: 分析基于本地仓库状态
  2. 最多100个讨论: GraphQL查询限制为前100个线程
  3. 每个线程最多10条评论: 评论获取限制为前10条
  4. 无文件历史: 无法分析完整的文件演变
  5. 需要身份验证: 必须拥有GitHub访问令牌
  6. 速率限制: 在大型PR上可能触发API限制

Error Handling

错误处理

Common Errors and Solutions

常见错误及解决方案

Error: gh: command not found
  • Cause: GitHub CLI not installed
  • Solution: Install with
    brew install gh
    or platform equivalent
Error: To get started with GitHub CLI, run: gh auth login
  • Cause: Not authenticated with GitHub
  • Solution: Run
    gh auth login
    and follow prompts
Error: GraphQL: Could not resolve to a PullRequest
  • Cause: Invalid PR number or URL
  • Solution: Verify PR exists and URL is correct
Error: Resource not accessible by personal access token
  • Cause: Insufficient permissions
  • Solution: Re-authenticate with
    gh auth refresh -s repo
Error: API rate limit exceeded
  • Cause: Too many API requests
  • Solution: Wait for rate limit reset (check
    gh api rate_limit
    )
错误:gh: command not found
  • 原因: GitHub CLI未安装
  • 解决方案: 使用
    brew install gh
    或对应平台的安装方式
错误:To get started with GitHub CLI, run: gh auth login
  • 原因: 未通过GitHub身份验证
  • 解决方案: 运行
    gh auth login
    并按照提示操作
错误:GraphQL: Could not resolve to a PullRequest
  • 原因: PR编号或URL无效
  • 解决方案: 验证PR是否存在且URL正确
错误:Resource not accessible by personal access token
  • 原因: 权限不足
  • 解决方案: 使用
    gh auth refresh -s repo
    重新验证
错误:API rate limit exceeded
  • 原因: API请求过多
  • 解决方案: 等待速率限制重置(使用
    gh api rate_limit
    检查)

Advanced Features

高级功能

Batch Processing

批量处理

For PRs with many discussions:
bash
undefined
对于包含大量讨论的PR:
bash
undefined

Process in batches of 10

以10个为一批处理

for i in {0..9}; do

Process discussion $i

Add delay to avoid rate limiting

sleep 1 done
undefined
for i in {0..9}; do

处理第i个讨论

添加延迟以避免速率限制

sleep 1 done
undefined

Draft Responses

草稿回复

Before posting, optionally show draft responses to user:
Draft response for [file]:[line]:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[Response text]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Post this response? [y/n]
发布前,可选择向用户显示草稿回复:
[文件]:[行号]的草稿回复:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[回复文本]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

是否发布此回复? [y/n]

Filter by Reviewer

按评审者筛选

Process discussions from specific reviewer:
bash
undefined
处理特定评审者的讨论:
bash
undefined

Filter threads by comment author

按评论作者筛选线程

jq '.data.repository.pullRequest.reviewThreads.nodes[] | select(.comments.nodes[0].author.login == "specific-reviewer")'
undefined
jq '.data.repository.pullRequest.reviewThreads.nodes[] | select(.comments.nodes[0].author.login == "specific-reviewer")'
undefined

References

参考资料

Notes

注意事项

  • Always post comments before resolving threads (order matters)
  • Responses should be professional and technically accurate
  • Include code snippets when clarifying implementation details
  • Reference specific lines/commits to support arguments
  • Never resolve threads without explanation
  • Escalate to user when feedback is ambiguous or requires design decision
  • 始终先发布评论再解决线程(顺序很重要)
  • 回复应专业且技术准确
  • 澄清实现细节时附上代码片段
  • 引用特定行/提交以支持论点
  • 切勿在未解释的情况下解决线程
  • 当反馈模糊或需要设计决策时,升级给用户处理