Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/github/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@ func AddCommentToPendingReview(t translations.TranslationHelperFunc) inventory.S
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!

Reviews struct {
Nodes []struct {
ID githubv4.ID
Expand Down Expand Up @@ -1788,6 +1789,7 @@ func AddCommentToPendingReview(t translations.TranslationHelperFunc) inventory.S
} `graphql:"addPullRequestReviewThread(input: $input)"`
}

pullRequestID := getLatestReviewForViewerQuery.Repository.PullRequest.ID
if err := client.Mutate(
ctx,
&addPullRequestReviewThreadMutation,
Expand All @@ -1799,6 +1801,7 @@ func AddCommentToPendingReview(t translations.TranslationHelperFunc) inventory.S
Side: newGQLStringlikePtr[githubv4.DiffSide](params.Side),
StartLine: newGQLIntPtr(params.StartLine),
StartSide: newGQLStringlikePtr[githubv4.DiffSide](params.StartSide),
PullRequestID: &pullRequestID,
PullRequestReviewID: &review.ID,
},
nil,
Expand Down
50 changes: 50 additions & 0 deletions pkg/github/pullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,7 @@ func TestAddPullRequestReviewCommentToPendingReview(t *testing.T) {
owner: "owner",
repo: "repo",
prNum: 42,
prID: "PR_kwDOTest123",

reviews: []getLatestPendingReviewQueryReview{
{
Expand All @@ -2756,6 +2757,7 @@ func TestAddPullRequestReviewCommentToPendingReview(t *testing.T) {
Side: githubv4mock.Ptr(githubv4.DiffSideRight),
StartLine: githubv4.NewInt(5),
StartSide: githubv4mock.Ptr(githubv4.DiffSideRight),
PullRequestID: githubv4.NewID("PR_kwDOTest123"),
PullRequestReviewID: githubv4.NewID("PR_kwDODKw3uc6WYN1T"),
},
nil,
Expand Down Expand Up @@ -2788,6 +2790,7 @@ func TestAddPullRequestReviewCommentToPendingReview(t *testing.T) {
owner: "owner",
repo: "repo",
prNum: 42,
prID: "PR_kwDOTest123",

reviews: []getLatestPendingReviewQueryReview{
{
Expand All @@ -2813,6 +2816,7 @@ func TestAddPullRequestReviewCommentToPendingReview(t *testing.T) {
Side: githubv4mock.Ptr(githubv4.DiffSideRight),
StartLine: nil,
StartSide: nil,
PullRequestID: githubv4.NewID("PR_kwDOTest123"),
PullRequestReviewID: githubv4.NewID("PR_kwDODKw3uc6WYN1T"),
},
nil,
Expand Down Expand Up @@ -3183,11 +3187,57 @@ type getLatestPendingReviewQueryParams struct {
owner string
repo string
prNum int32
prID string // Optional: include PR ID when needed for AddPullRequestReviewThread mutation

reviews []getLatestPendingReviewQueryReview
}

func getLatestPendingReviewQuery(p getLatestPendingReviewQueryParams) githubv4mock.Matcher {
// If prID is provided, include it in the query structure (needed for AddPullRequestReviewThread)
if p.prID != "" {
return githubv4mock.NewQueryMatcher(
struct {
Repository struct {
PullRequest struct {
ID githubv4.ID
Reviews struct {
Nodes []struct {
ID githubv4.ID
State githubv4.PullRequestReviewState
URL githubv4.URI
}
} `graphql:"reviews(first: 1, author: $author)"`
} `graphql:"pullRequest(number: $prNum)"`
} `graphql:"repository(owner: $owner, name: $name)"`
}{},
map[string]any{
"author": githubv4.String(p.author),
"owner": githubv4.String(p.owner),
"name": githubv4.String(p.repo),
"prNum": githubv4.Int(p.prNum),
},
githubv4mock.DataResponse(
map[string]any{
"repository": map[string]any{
"pullRequest": map[string]any{
"id": p.prID,
"reviews": map[string]any{
"nodes": []any{
map[string]any{
"id": p.reviews[0].id,
"state": p.reviews[0].state,
"url": p.reviews[0].url,
},
},
},
},
},
},
),
)
}

// Default: without PR ID (for SubmitPendingPullRequestReview and DeletePendingPullRequestReview)
return githubv4mock.NewQueryMatcher(
struct {
Repository struct {
Expand Down