背景:解決したい課題
普段、複数のAIを使ってPRのレビューをしてもらっています。(Copilot、Codex、Gemini、Claude Code GitHub Actions, etc.)
その結果、一つのPRのレビューコメントが増えてきて、以下のような問題が発生します:
- どのコメントに対応が必要か分からない - 既に修正済みのコメントと未対応のコメントが混在
- コメントへの返信が漏れる - 修正したのにコメントをresolveし忘れる
- 異なるAIレビューによる似たようなコメントの重複 - 関連する複数のコメントをバラバラに対応してしまう
- 現在のコード状態との乖離 - 後続のコミットでコードが変わり、コメントが古くなっている
これらを手動で確認・整理するのは時間がかかり、対応漏れによるコード品質の低下にもつながります。
この課題感は、普段私が、[Claude Code] PR reviewコメントをResolveするCustom Slash Commandを使ってReview comment一つ一つ修正しているときに、複数コメントあったときにどれは対応する必要あるか自分でチェックするのを簡易化したいなーと思ったことから始まりました。
機能
このコマンドは、PRのレビューコメントを自動的に分析し、適切な対応を提案します:
1. レビューコメントの自動分類
各コメントを現在のコード状態と照らし合わせて分類:
- valid: まだ対応が必要なコメント
- fixed: 既に修正済みのコメント(どのコミットで修正されたかも特定)
- outdated: コードが変更されて該当しなくなったコメント
2. 類似コメントのグループ化
validなコメントを以下の基準でグループ化:
- 同じファイル/関数に関するコメント
- 関連する懸念事項(例:エラーハンドリング関連の複数コメント)
- 同じ種類の問題(例:テスト、ドキュメントなど)
複数のAIによるReviewがあるので、このステップを入れました。
3. アクションプランの提示
各コメントグループに対して具体的な対応方法を提案:
- validコメント: グループごとに対応方針を提案し、レビュアーに確認を求める返信を用意
- fixedコメント: 修正したコミットSHAを含む返信を用意し、スレッドをresolve
- outdatedコメント: 理由を説明する返信を用意し、スレッドをresolve
勝手にコメントをバンバン書かれると他の人と協業している場合には、迷惑になるので、必ずAction Planを自分でレビューしてから実行してもらいます。
4. 一括実行
確認後、以下を自動実行:
- 各コメントへの返信投稿
- fixed/outdatedコメントのスレッドresolve
- validコメントは返信のみ(レビュアーの確認を待つためresolveしない)
実行により、不要なコメントをResolveして、Validコメントに対して、これからの対応方針を共有しておきます。
5. validコメントへの対応
返信投稿後、実際にコードを修正する場合は別コマンドを使用するかどうかを訪ねてきます。
/resolve-gh-review-comment <comment_url_1> <comment_url_2> "追加のコンテキスト"
修正する場合は、コマンドを実行します。
詳細はこちらを参照してください。
使い方
基本的な使用方法
# PR番号を指定してコメントをチェック
/check-gh-review-comments 123
実行の流れ
- コマンド実行: PR番号を指定
- 分析結果の確認: コメントの分類とアクションプランが表示される
- 実行確認: 提案された対応でよければ確認
- 自動実行: 返信投稿とスレッド解決が自動で行われる
出力例
## Review Comment Analysis for PR #123
### Valid Comments (require action)
**Group 1: Error Handling** (3 comments)
- Comment r1234 (@reviewer): Add error handling in webhook.ts:45
- Comment r1235 (@reviewer): Missing try-catch in route.ts:23
**Proposed Action:**
Reply with: "Thank you for the feedback. I'll address these error handling concerns..."
### Fixed Comments (will reply and resolve)
- Comment r1236 (@reviewer): Extract logic to usecase
**Reply:** "Fixed in commit 864e3fe. Extracted webhook processing logic..."
### Outdated Comments (will reply and resolve)
- Comment r1237 (@reviewer): Use async/await instead of .then()
**Reply:** "This code has been refactored and now uses async/await..."
コマンド /check-gh-review-comments
slash commandの定義は以下です。
# Check GitHub PR Review Comments
---
description: Check and categorize all review comments on a PR
argument-hint: <pr_number>
---
This command analyzes all review comments on a GitHub Pull Request, categorizes them, and suggests actions.
## Steps
### 1. Extract PR Number
Extract PR number from $ARGUMENTS.
If PR number is not specified, ask the user to input the pr number.
### 2. Fetch All Review Comments
Fetch only **unresolved** review threads using GraphQL API:
```bash
gh api graphql -f query='
query {
repository(owner: "{owner}", name: "{repo}") {
pullRequest(number: {pr_number}) {
reviewThreads(first: 100) {
nodes {
id
isResolved
comments(first: 10) {
nodes {
id
databaseId
author {
login
}
body
path
line
url
createdAt
}
}
}
}
}
}
}'
```
**Filter criteria:**
- Only process threads where `isResolved: false`
- Skip all resolved threads automatically
- This ensures you only analyze comments that still require attention
### 3. Analyze Each Comment
For each review comment, determine its current status by:
1. **Reading the comment content** - What was the reviewer's concern?
2. **Checking the current code** - Read the file at the commented path
3. **Classifying the comment**:
- **valid**: Issue still exists and needs to be addressed
- **fixed**: Issue has been fixed in a subsequent commit
- **outdated**: Code has changed and comment no longer applies
### 4. Group Valid Comments
Group valid comments by similarity:
- Same file/function
- Related concerns (e.g., multiple comments about error handling)
- Same type of issue (e.g., all about testing, documentation, etc.)
### 5. Present Action Plan
For each group/comment, suggest an action:
**For valid comments:**
- Group similar comments together
- Suggest fix approach
- Plan to reply with proposed solution for reviewer confirmation
**For fixed comments:**
- Identify the commit that fixed it
- Plan to reply: "Fixed in commit {sha}. {description}"
- Plan to resolve the thread
**For outdated comments:**
- Explain why it's outdated
- Plan to reply: "This is no longer applicable because {reason}"
- Plan to resolve the thread
### 6. Show Summary and Get Confirmation
Present a structured summary:
````
## Review Comment Analysis for PR #{pr_number}
### Valid Comments (require action)
**Group 1: Error Handling** (3 comments)
- Comment r{id1} (@{author}): Add error handling in webhook.ts:45
- Comment r{id2} (@{author}): Missing try-catch in route.ts:23
- Comment r{id3} (@{author}): Handle network errors in client.ts:67
**Proposed Action:**
Reply with: "Thank you for the feedback. I'll address these error handling concerns with the following approach:
1. Add comprehensive try-catch blocks
2. Implement proper error logging
3. Add error boundary for client components
I'll implement this and update in the next commit."
**Group 2: Documentation** (1 comment)
- Comment r{id4} (@{author}): Add JSDoc for verifyJWT function
**Proposed Action:**
Reply with: "I'll add comprehensive JSDoc comments for all exported functions in the next commit."
### Fixed Comments (will reply and resolve)
- Comment r{id5} (@{author}): Extract logic to usecase
**Reply:** "Fixed in commit 864e3fe. Extracted webhook processing logic to dedicated usecase, reducing route from 197 to 34 lines."
- Comment r{id6} (@{author}): Remove DISABLE_PUBSUB_AUTH
**Reply:** "Addressed in commit {sha}. Removed DISABLE_PUBSUB_AUTH for security hardening. Tests now use proper mocking."
### Outdated Comments (will reply and resolve)
- Comment r{id7} (@{author}): Use async/await instead of .then()
**Reply:** "This code has been refactored and now uses async/await throughout."
---
**Total:** X valid comments (Y groups), Z fixed, W outdated
---
Do you want to proceed with these actions?
````
### 7. Execute Actions (after user confirmation)
For each action:
1. **Reply to comment:**
```bash
gh api -X POST repos/{owner}/{repo}/pulls/{pr_number}/comments/{comment_id}/replies \
-f body="{reply_message}"
```
2. **Resolve thread (for fixed/outdated):**
First, get thread ID:
```bash
gh api graphql -f query='
query {
repository(owner: "{owner}", name: "{repo}") {
pullRequest(number: {pr_number}) {
reviewThreads(first: 100) {
nodes {
id
isResolved
comments(first: 1) {
nodes {
databaseId
}
}
}
}
}
}
}'
```
Then resolve:
```bash
gh api graphql -f query='
mutation {
resolveReviewThread(input: {threadId: "{thread_id}"}) {
thread {
isResolved
}
}
}'
```
3. **For valid comments requiring code changes:**
- Only post the reply with proposed approach
- DO NOT resolve (wait for reviewer confirmation)
- DO NOT implement changes (this command only handles communication)
### 8. Ask user for next steps for implementation (valid comments)
After executing the above actions (replying to fixed/outdated comments), present the user with options for implementing fixes for valid comments.
**Show this message to the user:**
---
If you want to implement fixes for valid comments, use:
```bash
/resolve-gh-review-comment <comment_url_1> <comment_url_2> ... "Additional context message"
```
**Example for grouped comments:**
```bash
/resolve-gh-review-comment \
https://github.com/{owner}/{repo}/pull/{pr_number}#discussion_r{id1} \
https://github.com/{owner}/{repo}/pull/{pr_number}#discussion_r{id2} \
https://github.com/{owner}/{repo}/pull/{pr_number}#discussion_r{id3} \
"These comments are related and can be addressed with a single implementation plan for comprehensive error handling."
```
**Example for single comment:**
```bash
/resolve-gh-review-comment \
https://github.com/{owner}/{repo}/pull/{pr_number}#discussion_r{id4} \
"Will add JSDoc documentation for all public functions."
```
## Important Notes
- **This command does NOT implement code changes** - it only manages review comment communication
- Valid comments get a proposed solution but are NOT resolved (wait for reviewer feedback)
- Fixed/outdated comments are replied to AND resolved
- Always verify current code state before classifying comments
- Group similar valid comments to avoid repetitive responses
- Use clear, professional language in all replies
- Include commit SHAs when referencing fixes
## Example Usage
```bash
# Check all review comments on a PR
/check-gh-review-comments 123
```
The command will:
1. Fetch all review comments
2. Analyze current code state
3. Categorize each comment
4. Group valid comments by similarity
5. Present action plan
6. Wait for your confirmation
7. Execute replies and thread resolutions