Skip to content

Add scripts and rules for Claude Code to respond to bot PR review comments #126

Description

@ikuwow

Summary

Claude Code に PR レビューコメントへの返信と resolve を任せたい。
人間のコメントには絶対に触らせず、AI/bot コメントのみを対象にする。
スクリプト側に bot チェックを内蔵して、ルール違反を構造的に防ぐ。

Background

  • gh ネイティブ CLI では review thread への返信や resolve ができない
  • GraphQL API (addPullRequestReviewThreadReply, resolveReviewThread) を使う必要がある
  • __typename フィールドで Bot/User を判別可能(PR Add PreToolUse hook to block cd chaining #124 で動作確認済み)
  • 現状 gh api * -f * が ask リストにあるため、GraphQL は全て都度確認が出る

Plan

1. スクリプト群 (bin/)

gh-pr-review-threads <owner/repo> <pr-number>

  • Read-only: PR の review thread 一覧を JSON で出力
  • 各 thread の ID, isResolved, comments (author login, __typename, body) を含む
  • Permission: allow

gh-pr-thread-reply <owner/repo> <pr-number> <thread-id> <body>

  • Bot チェック内蔵: thread の最初のコメントが bot でなければ拒否 (exit 1)
  • Bot 判定: __typename == "Bot" OR login が known list に含まれる
    • Known list: github-actions[bot], dependabot[bot], copilot-pull-request-reviewer, renovate[bot]
  • GraphQL addPullRequestReviewThreadReply mutation で返信
  • Permission: allow (bot チェック済みのため)

gh-pr-thread-resolve <owner/repo> <pr-number> <thread-id>

  • Bot チェック内蔵: reply と同じロジック
  • GraphQL resolveReviewThread mutation で resolve
  • Permission: allow (bot チェック済みのため)

共通仕様

  • bot チェックロジックは関数として共有
  • set -eu, shellcheck pass
  • エラー時は理由を stderr に出力

2. ルールファイル (claude/rules/pr-review-response.md)

  • Bot コメント: gh-pr-thread-reply で返信 → gh-pr-thread-resolve で resolve
  • 人間コメント: 内容をユーザーにサマリー報告するのみ。返信・resolve 禁止
  • gh api graphql を直接使って返信・resolve しない(スクリプト経由を強制)

3. claude/settings.json 変更

allow に追加:

  • Bash(gh-pr-review-threads *)
  • Bash(gh-pr-thread-reply *)
  • Bash(gh-pr-thread-resolve *)

ask に追加:

  • Bash(gh pr comment *) (top-level PR comment)

Verification

  • gh-pr-review-threads ikuwow/dotfiles 124 で JSON が返る
  • gh-pr-thread-reply に人間 thread ID → 拒否される
  • gh-pr-thread-reply に bot thread ID → 返信できる
  • shellcheck pass
  • settings.json valid JSON

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions