Skip to content

Commit 91b767e

Browse files
Fix add_comment_to_pending_review for fork PRs
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
1 parent 80b0306 commit 91b767e

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

pkg/github/pullrequests.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,7 @@ func AddCommentToPendingReview(t translations.TranslationHelperFunc) inventory.S
17431743
var getLatestReviewForViewerQuery struct {
17441744
Repository struct {
17451745
PullRequest struct {
1746+
ID githubv4.ID
17461747
Reviews struct {
17471748
Nodes []struct {
17481749
ID githubv4.ID
@@ -1788,6 +1789,7 @@ func AddCommentToPendingReview(t translations.TranslationHelperFunc) inventory.S
17881789
} `graphql:"addPullRequestReviewThread(input: $input)"`
17891790
}
17901791

1792+
pullRequestID := getLatestReviewForViewerQuery.Repository.PullRequest.ID
17911793
if err := client.Mutate(
17921794
ctx,
17931795
&addPullRequestReviewThreadMutation,
@@ -1799,6 +1801,7 @@ func AddCommentToPendingReview(t translations.TranslationHelperFunc) inventory.S
17991801
Side: newGQLStringlikePtr[githubv4.DiffSide](params.Side),
18001802
StartLine: newGQLIntPtr(params.StartLine),
18011803
StartSide: newGQLStringlikePtr[githubv4.DiffSide](params.StartSide),
1804+
PullRequestID: &pullRequestID,
18021805
PullRequestReviewID: &review.ID,
18031806
},
18041807
nil,

pkg/github/pullrequests_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,7 @@ func TestAddPullRequestReviewCommentToPendingReview(t *testing.T) {
27312731
owner: "owner",
27322732
repo: "repo",
27332733
prNum: 42,
2734+
prID: "PR_kwDOTest123",
27342735

27352736
reviews: []getLatestPendingReviewQueryReview{
27362737
{
@@ -2756,6 +2757,7 @@ func TestAddPullRequestReviewCommentToPendingReview(t *testing.T) {
27562757
Side: githubv4mock.Ptr(githubv4.DiffSideRight),
27572758
StartLine: githubv4.NewInt(5),
27582759
StartSide: githubv4mock.Ptr(githubv4.DiffSideRight),
2760+
PullRequestID: githubv4.NewID("PR_kwDOTest123"),
27592761
PullRequestReviewID: githubv4.NewID("PR_kwDODKw3uc6WYN1T"),
27602762
},
27612763
nil,
@@ -2788,6 +2790,7 @@ func TestAddPullRequestReviewCommentToPendingReview(t *testing.T) {
27882790
owner: "owner",
27892791
repo: "repo",
27902792
prNum: 42,
2793+
prID: "PR_kwDOTest123",
27912794

27922795
reviews: []getLatestPendingReviewQueryReview{
27932796
{
@@ -2813,6 +2816,7 @@ func TestAddPullRequestReviewCommentToPendingReview(t *testing.T) {
28132816
Side: githubv4mock.Ptr(githubv4.DiffSideRight),
28142817
StartLine: nil,
28152818
StartSide: nil,
2819+
PullRequestID: githubv4.NewID("PR_kwDOTest123"),
28162820
PullRequestReviewID: githubv4.NewID("PR_kwDODKw3uc6WYN1T"),
28172821
},
28182822
nil,
@@ -3183,11 +3187,57 @@ type getLatestPendingReviewQueryParams struct {
31833187
owner string
31843188
repo string
31853189
prNum int32
3190+
prID string // Optional: include PR ID when needed for AddPullRequestReviewThread mutation
31863191

31873192
reviews []getLatestPendingReviewQueryReview
31883193
}
31893194

31903195
func getLatestPendingReviewQuery(p getLatestPendingReviewQueryParams) githubv4mock.Matcher {
3196+
// If prID is provided, include it in the query structure (needed for AddPullRequestReviewThread)
3197+
if p.prID != "" {
3198+
return githubv4mock.NewQueryMatcher(
3199+
struct {
3200+
Repository struct {
3201+
PullRequest struct {
3202+
ID githubv4.ID
3203+
Reviews struct {
3204+
Nodes []struct {
3205+
ID githubv4.ID
3206+
State githubv4.PullRequestReviewState
3207+
URL githubv4.URI
3208+
}
3209+
} `graphql:"reviews(first: 1, author: $author)"`
3210+
} `graphql:"pullRequest(number: $prNum)"`
3211+
} `graphql:"repository(owner: $owner, name: $name)"`
3212+
}{},
3213+
map[string]any{
3214+
"author": githubv4.String(p.author),
3215+
"owner": githubv4.String(p.owner),
3216+
"name": githubv4.String(p.repo),
3217+
"prNum": githubv4.Int(p.prNum),
3218+
},
3219+
githubv4mock.DataResponse(
3220+
map[string]any{
3221+
"repository": map[string]any{
3222+
"pullRequest": map[string]any{
3223+
"id": p.prID,
3224+
"reviews": map[string]any{
3225+
"nodes": []any{
3226+
map[string]any{
3227+
"id": p.reviews[0].id,
3228+
"state": p.reviews[0].state,
3229+
"url": p.reviews[0].url,
3230+
},
3231+
},
3232+
},
3233+
},
3234+
},
3235+
},
3236+
),
3237+
)
3238+
}
3239+
3240+
// Default: without PR ID (for SubmitPendingPullRequestReview and DeletePendingPullRequestReview)
31913241
return githubv4mock.NewQueryMatcher(
31923242
struct {
31933243
Repository struct {

0 commit comments

Comments
 (0)