Fix add_comment_to_pending_review for fork PRs#1749
Closed
SamMorrowDrums wants to merge 1 commit intomainfrom
Closed
Fix add_comment_to_pending_review for fork PRs#1749SamMorrowDrums wants to merge 1 commit intomainfrom
SamMorrowDrums wants to merge 1 commit intomainfrom
Conversation
The addPullRequestReviewThread GraphQL mutation requires the PullRequestID field to correctly identify the pull request context for fork PRs. Without this field, the API returns null for the thread ID, causing comments to fail. This adds the PullRequestID to both the query (to fetch it) and the mutation input, fixing the issue for fork-based pull requests. Fixes #1748
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the add_comment_to_pending_review tool was failing for pull requests originating from forked repositories. The fix adds the PullRequestID field to the GraphQL mutation, which GitHub's API requires to properly resolve the context for fork PRs.
Key changes:
- Modified the GraphQL query to fetch
PullRequest.IDin addition to review information - Added
PullRequestIDto theAddPullRequestReviewThreadInputmutation parameters - Updated test mocks to support both query structures (with and without PR ID) for different use cases
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/github/pullrequests.go | Added ID field to query struct and PullRequestID to mutation input to support fork PR review comments |
| pkg/github/pullrequests_test.go | Updated test helper to conditionally include PR ID in query mock and added prID parameter to affected test cases |
SamMorrowDrums
commented
Jan 6, 2026
Collaborator
Author
SamMorrowDrums
left a comment
There was a problem hiding this comment.
Testing add_comment_to_pending_review on a non-fork PR - this works! The fix is confirmed working for same-repo PRs.
| var getLatestReviewForViewerQuery struct { | ||
| Repository struct { | ||
| PullRequest struct { | ||
| ID githubv4.ID |
Collaborator
Author
There was a problem hiding this comment.
This is the key fix - adding PullRequestID to the query structure!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1748
The
add_comment_to_pending_reviewtool was failing for pull requests from forks because theaddPullRequestReviewThreadGraphQL mutation requires thePullRequestIDfield to correctly identify the pull request context.Problem
When adding review comments to PRs from forks, the API was returning
nullfor the thread ID with the error:This happened even when all parameters were correct, and worked fine for PRs from the same repo.
Root Cause
The
AddPullRequestReviewThreadInputGraphQL input has two optional ID fields:PullRequestID- The node ID of the pull requestPullRequestReviewID- The Node ID of the reviewThe code was only providing
PullRequestReviewID. For fork PRs, GitHub's API needsPullRequestIDto correctly resolve the context.This appears to be a pre-existing bug rather than a regression from the consolidation work in #1192. The
add_comment_to_pending_reviewtool was not modified during that consolidation. The issue likely became more visible due to stricter API validation on GitHub's side.Related: https://github.com/orgs/community/discussions/182548
Fix
PullRequest.IDPullRequestIDto the mutation inputTesting