Skip to content

Commit 192ca0b

Browse files
committed
Address comments from Copilot review
1 parent 6411325 commit 192ca0b

2 files changed

Lines changed: 29 additions & 24 deletions

File tree

pkg/github/discussions.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -622,14 +622,20 @@ func AddDiscussionComment(t translations.TranslationHelperFunc) inventory.Server
622622
},
623623
[]scopes.Scope{scopes.Repo},
624624
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
625-
// Decode params
626-
var params struct {
627-
Owner string
628-
Repo string
629-
DiscussionNumber int32
630-
Body string
625+
owner, err := RequiredParam[string](args, "owner")
626+
if err != nil {
627+
return utils.NewToolResultError(err.Error()), nil, nil
631628
}
632-
if err := mapstructure.WeakDecode(args, &params); err != nil {
629+
repo, err := RequiredParam[string](args, "repo")
630+
if err != nil {
631+
return utils.NewToolResultError(err.Error()), nil, nil
632+
}
633+
discussionNumber, err := RequiredInt(args, "discussionNumber")
634+
if err != nil {
635+
return utils.NewToolResultError(err.Error()), nil, nil
636+
}
637+
body, err := RequiredParam[string](args, "body")
638+
if err != nil {
633639
return utils.NewToolResultError(err.Error()), nil, nil
634640
}
635641
client, err := deps.GetGQLClient(ctx)
@@ -646,9 +652,9 @@ func AddDiscussionComment(t translations.TranslationHelperFunc) inventory.Server
646652
} `graphql:"repository(owner: $owner, name: $repo)"`
647653
}
648654
vars := map[string]any{
649-
"owner": githubv4.String(params.Owner),
650-
"repo": githubv4.String(params.Repo),
651-
"discussionNumber": githubv4.Int(params.DiscussionNumber),
655+
"owner": githubv4.String(owner),
656+
"repo": githubv4.String(repo),
657+
"discussionNumber": githubv4.Int(discussionNumber), // #nosec G115 - discussion numbers are always small positive integers
652658
}
653659
if err := client.Query(ctx, &q, vars); err != nil {
654660
return utils.NewToolResultError(err.Error()), nil, nil
@@ -657,7 +663,7 @@ func AddDiscussionComment(t translations.TranslationHelperFunc) inventory.Server
657663
// Add the comment using the discussion's node ID
658664
input := githubv4.AddDiscussionCommentInput{
659665
DiscussionID: q.Repository.Discussion.ID,
660-
Body: githubv4.String(params.Body),
666+
Body: githubv4.String(body),
661667
}
662668

663669
replyToCommentNodeID, err := OptionalParam[string](args, "replyToCommentNodeID")
@@ -745,11 +751,12 @@ func UpdateDiscussionComment(t translations.TranslationHelperFunc) inventory.Ser
745751
},
746752
[]scopes.Scope{scopes.Repo},
747753
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
748-
var params struct {
749-
CommentNodeID string
750-
Body string
754+
commentNodeID, err := RequiredParam[string](args, "commentNodeID")
755+
if err != nil {
756+
return utils.NewToolResultError(err.Error()), nil, nil
751757
}
752-
if err := mapstructure.WeakDecode(args, &params); err != nil {
758+
body, err := RequiredParam[string](args, "body")
759+
if err != nil {
753760
return utils.NewToolResultError(err.Error()), nil, nil
754761
}
755762
client, err := deps.GetGQLClient(ctx)
@@ -758,8 +765,8 @@ func UpdateDiscussionComment(t translations.TranslationHelperFunc) inventory.Ser
758765
}
759766

760767
input := githubv4.UpdateDiscussionCommentInput{
761-
CommentID: githubv4.ID(params.CommentNodeID),
762-
Body: githubv4.String(params.Body),
768+
CommentID: githubv4.ID(commentNodeID),
769+
Body: githubv4.String(body),
763770
}
764771

765772
var mutation struct {
@@ -813,10 +820,8 @@ func DeleteDiscussionComment(t translations.TranslationHelperFunc) inventory.Ser
813820
},
814821
[]scopes.Scope{scopes.Repo},
815822
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
816-
var params struct {
817-
CommentNodeID string
818-
}
819-
if err := mapstructure.WeakDecode(args, &params); err != nil {
823+
commentNodeID, err := RequiredParam[string](args, "commentNodeID")
824+
if err != nil {
820825
return utils.NewToolResultError(err.Error()), nil, nil
821826
}
822827
client, err := deps.GetGQLClient(ctx)
@@ -825,7 +830,7 @@ func DeleteDiscussionComment(t translations.TranslationHelperFunc) inventory.Ser
825830
}
826831

827832
input := githubv4.DeleteDiscussionCommentInput{
828-
ID: githubv4.ID(params.CommentNodeID),
833+
ID: githubv4.ID(commentNodeID),
829834
}
830835

831836
var mutation struct {
@@ -888,7 +893,7 @@ func SetDiscussionCommentAnswer(t translations.TranslationHelperFunc) inventory.
888893
return utils.NewToolResultError(err.Error()), nil, nil
889894
}
890895
if _, ok := args["isAnswer"]; !ok {
891-
return utils.NewToolResultError("isAnswer is required"), nil, nil
896+
return utils.NewToolResultError("missing required parameter: isAnswer"), nil, nil
892897
}
893898
isAnswer, err := OptionalParam[bool](args, "isAnswer")
894899
if err != nil {

pkg/github/discussions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ func Test_SetDiscussionCommentAnswer(t *testing.T) {
16781678
},
16791679
mockedClient: githubv4mock.NewMockedHTTPClient(),
16801680
expectToolError: true,
1681-
expectedErrMsg: "isAnswer is required",
1681+
expectedErrMsg: "missing required parameter: isAnswer",
16821682
},
16831683
}
16841684

0 commit comments

Comments
 (0)