| 1 | # PR Review Thread Resolution via GraphQL |
| 2 | |
| 3 | confidence: medium |
| 4 | discovered_by: Leela (PR workflow standardization) |
| 5 | date: 2026-05-19 |
| 6 | |
| 7 | ## Pattern |
| 8 | |
| 9 | Resolve pull request review threads programmatically using GitHub's GraphQL API. This enables: |
| 10 | 1. Automated responses to review comments |
| 11 | 2. Marking conversations as resolved without manual UI interaction |
| 12 | 3. Audit-trail-preserving replies (comment visible in history) |
| 13 | 4. Integration with workflow automation for issue resolution and documentation updates |
| 14 | |
| 15 | ## When to Use |
| 16 | |
| 17 | - Confirming issue fixes in PR review threads |
| 18 | - Updating review comments with implementation details |
| 19 | - Resolving conversations after changes are made |
| 20 | - Automating feedback acknowledgment in CI/CD workflows |
| 21 | - Multi-agent handoff scenarios where one agent acknowledges another's review |
| 22 | |
| 23 | ## Implementation |
| 24 | |
| 25 | ### GraphQL Mutation Pattern |
| 26 | |
| 27 | ```graphql |
| 28 | mutation { |
| 29 | addPullRequestReviewThreadReply(input: { |
| 30 | threadId: "PRRT_kwDOSgq4hM6C3UXy" |
| 31 | body: "✅ Fixed: [Description of change]" |
| 32 | }) { |
| 33 | comment { |
| 34 | id |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | ``` |
| 39 | |
| 40 | ### How to Get Thread ID |
| 41 | |
| 42 | 1. Query the PR to list review threads: |
| 43 | ```graphql |
| 44 | query { |
| 45 | repository(owner: "owner", name: "repo") { |
| 46 | pullRequest(number: 123) { |
| 47 | reviewThreads(first: 10) { |
| 48 | nodes { |
| 49 | id |
| 50 | isResolved |
| 51 | comments(first: 1) { |
| 52 | nodes { |
| 53 | body |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | ``` |
| 62 | |
| 63 | 2. Extract the `id` field (e.g., `PRRT_kwDOSgq4hM6C3UXy`) |
| 64 | 3. Use it in the `addPullRequestReviewThreadReply` mutation |
| 65 | |
| 66 | ### CLI Integration |
| 67 | |
| 68 | ```bash |
| 69 | # Store thread IDs from PR |
| 70 | THREAD_IDS=$(gh api graphql -f query=' |
| 71 | query { |
| 72 | repository(owner: "$OWNER", name: "$REPO") { |
| 73 | pullRequest(number: $PR_NUMBER) { |
| 74 | reviewThreads(first: 10) { |
| 75 | nodes { |
| 76 | id |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | ' -F OWNER=owner -F REPO=repo -F PR_NUMBER=123 --jq '.data.repository.pullRequest.reviewThreads.nodes[].id') |
| 83 | |
| 84 | # Reply to each thread |
| 85 | for THREAD_ID in $THREAD_IDS; do |
| 86 | gh api graphql -f query=' |
| 87 | mutation { |
| 88 | addPullRequestReviewThreadReply(input: { |
| 89 | threadId: "$THREAD_ID" |
| 90 | body: "Fixed in commit abc123" |
| 91 | }) { |
| 92 | comment { id } |
| 93 | } |
| 94 | } |
| 95 | ' -F THREAD_ID="$THREAD_ID" |
| 96 | done |
| 97 | ``` |
| 98 | |
| 99 | ## Examples |
| 100 | |
| 101 | From `reply_thread1.graphql`: |
| 102 | |
| 103 | ```graphql |
| 104 | mutation { |
| 105 | addPullRequestReviewThreadReply(input: { |
| 106 | threadId: "PRRT_kwDOSgq4hM6C3UXy" |
| 107 | body: "✅ Fixed: Removed the submodule initialization instruction from the rollout checklist. The project does not use git submodules." |
| 108 | }) { |
| 109 | comment { |
| 110 | id |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | ``` |
| 115 | |
| 116 | ## Notes |
| 117 | |
| 118 | - Thread IDs are opaque identifiers; they cannot be easily reverse-engineered from PR/comment numbers |
| 119 | - Use `gh api graphql` for CLI-based GraphQL queries |
| 120 | - Replies are visible in the PR review thread history (not hidden) |
| 121 | - Marking as resolved requires a separate GraphQL call (not shown in this example) |
| 122 | - Authentication requires `repo` or `pull_request` scope |