Skip to content

Conversation

@SamMorrowDrums
Copy link
Collaborator

@SamMorrowDrums SamMorrowDrums commented Jan 6, 2026

Summary

Fixes #1748

The add_comment_to_pending_review tool was failing for pull requests from forks because the addPullRequestReviewThread GraphQL mutation requires the PullRequestID field to correctly identify the pull request context.

Problem

When adding review comments to PRs from forks, the API was returning null for the thread ID with the error:

Failed to add comment to pending review. Possible reasons:
  - The line number doesn't exist in the pull request diff
  - The file path is incorrect
  - The side (LEFT/RIGHT) is invalid for the specified line

This happened even when all parameters were correct, and worked fine for PRs from the same repo.

Root Cause

The AddPullRequestReviewThreadInput GraphQL input has two optional ID fields:

  • PullRequestID - The node ID of the pull request
  • PullRequestReviewID - The Node ID of the review

The code was only providing PullRequestReviewID. For fork PRs, GitHub's API needs PullRequestID to 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_review tool 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

  1. Modified the GraphQL query to also fetch PullRequest.ID
  2. Added PullRequestID to the mutation input

Testing

  • All existing tests pass
  • Updated test helper to support the new query structure
  • Lint passes

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
@SamMorrowDrums SamMorrowDrums requested a review from a team as a code owner January 6, 2026 17:16
Copilot AI review requested due to automatic review settings January 6, 2026 17:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ID in addition to review information
  • Added PullRequestID to the AddPullRequestReviewThreadInput mutation 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

Copy link
Collaborator Author

@SamMorrowDrums SamMorrowDrums left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key fix - adding PullRequestID to the query structure!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP server no longer allowing adding comments to pending reviews for fork PRs

2 participants