Skip to content
Open
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
14 changes: 14 additions & 0 deletions pkg/github/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,20 @@ func AddCommentToPendingReview(t translations.TranslationHelperFunc) inventory.S
return utils.NewToolResultError(err.Error()), nil, nil
}

// WeakDecode leaves an omitted field as its zero value, so without an
// explicit check a missing required argument (e.g. owner) would be
// sent to the GraphQL API and surface as a confusing downstream error
// ("Could not resolve to a Repository ...") instead of a clear
// missing-parameter message. Validate the required arguments up front.
for _, p := range []string{"owner", "repo", "path", "body", "subjectType"} {
if _, err := RequiredParam[string](args, p); err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
}
if _, err := RequiredInt(args, "pullNumber"); err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}

client, err := deps.GetGQLClient(ctx)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub GQL client", err), nil, nil
Expand Down
13 changes: 13 additions & 0 deletions pkg/github/pullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3575,6 +3575,19 @@ func TestAddPullRequestReviewCommentToPendingReview(t *testing.T) {
expectToolError: true,
expectedToolErrMsg: "Failed to add comment to pending review",
},
{
name: "missing required owner is reported instead of running the query",
mockedClient: githubv4mock.NewMockedHTTPClient(),
requestArgs: map[string]any{
"repo": "repo",
"pullNumber": float64(42),
"path": "file.go",
"body": "This is a test comment",
"subjectType": "LINE",
},
expectToolError: true,
expectedToolErrMsg: "missing required parameter: owner",
},
}

for _, tc := range tests {
Expand Down