Skip to content

Commit ea14878

Browse files
Validate positive comment IDs
Reject non-positive issue and pull request comment IDs in handlers and add the missing schema minimum for pull request review comment IDs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e522c77 commit ea14878

5 files changed

Lines changed: 31 additions & 0 deletions

File tree

pkg/github/__toolsnaps__/add_reply_to_pull_request_comment.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"commentId": {
1313
"description": "The numeric ID of the pull request review comment to reply or react to. Use the number from a #discussion_r... anchor, not the GraphQL thread node ID (PRRT_...).",
14+
"minimum": 1,
1415
"type": "number"
1516
},
1617
"owner": {

pkg/github/issues.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,9 @@ func AddIssueComment(t translations.TranslationHelperFunc) inventory.ServerTool
11661166
if err != nil {
11671167
return utils.NewToolResultError(err.Error()), nil, nil
11681168
}
1169+
if commentID < 1 {
1170+
return utils.NewToolResultError("comment_id must be greater than 0"), nil, nil
1171+
}
11691172
hasCommentID = true
11701173
}
11711174
body, hasBody, err := OptionalParamOK[string](args, "body")

pkg/github/issues_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4353,6 +4353,18 @@ func TestAddIssueComment(t *testing.T) {
43534353
expectToolError: true,
43544354
expectedToolErrMsg: "comment_id can only be provided when reaction is provided",
43554355
},
4356+
{
4357+
name: "negative comment_id",
4358+
requestArgs: map[string]any{
4359+
"owner": "owner",
4360+
"repo": "repo",
4361+
"issue_number": float64(42),
4362+
"comment_id": float64(-1),
4363+
"reaction": "heart",
4364+
},
4365+
expectToolError: true,
4366+
expectedToolErrMsg: "comment_id must be greater than 0",
4367+
},
43564368
{
43574369
name: "comment_id with body",
43584370
requestArgs: map[string]any{

pkg/github/pullrequests.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ func AddReplyToPullRequestComment(t translations.TranslationHelperFunc) inventor
12161216
"commentId": {
12171217
Type: "number",
12181218
Description: "The numeric ID of the pull request review comment to reply or react to. Use the number from a #discussion_r... anchor, not the GraphQL thread node ID (PRRT_...).",
1219+
Minimum: jsonschema.Ptr(1.0),
12191220
},
12201221
"body": {
12211222
Type: "string",
@@ -1255,6 +1256,9 @@ func AddReplyToPullRequestComment(t translations.TranslationHelperFunc) inventor
12551256
if err != nil {
12561257
return utils.NewToolResultError(err.Error()), nil, nil
12571258
}
1259+
if commentID < 1 {
1260+
return utils.NewToolResultError("commentId must be greater than 0"), nil, nil
1261+
}
12581262
body, hasBody, err := OptionalParamOK[string](args, "body")
12591263
if err != nil {
12601264
return utils.NewToolResultError(err.Error()), nil, nil

pkg/github/pullrequests_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4094,6 +4094,17 @@ func TestAddReplyToPullRequestComment(t *testing.T) {
40944094
expectToolError: true,
40954095
expectedToolErrMsg: "missing required parameter: commentId",
40964096
},
4097+
{
4098+
name: "negative commentId",
4099+
requestArgs: map[string]any{
4100+
"owner": "owner",
4101+
"repo": "repo",
4102+
"commentId": float64(-123),
4103+
"reaction": "rocket",
4104+
},
4105+
expectToolError: true,
4106+
expectedToolErrMsg: "commentId must be greater than 0",
4107+
},
40974108
{
40984109
name: "missing body and reaction",
40994110
requestArgs: map[string]any{

0 commit comments

Comments
 (0)