(ctx context.Context, client *githubv4.Client, args map[string]any)
| 682 | } |
| 683 | |
| 684 | func addDiscussionComment(ctx context.Context, client *githubv4.Client, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 685 | owner, err := RequiredParam[string](args, "owner") |
| 686 | if err != nil { |
| 687 | return utils.NewToolResultError(err.Error()), nil, nil |
| 688 | } |
| 689 | repo, err := RequiredParam[string](args, "repo") |
| 690 | if err != nil { |
| 691 | return utils.NewToolResultError(err.Error()), nil, nil |
| 692 | } |
| 693 | discussionNumber, err := RequiredInt(args, "discussionNumber") |
| 694 | if err != nil { |
| 695 | return utils.NewToolResultError(err.Error()), nil, nil |
| 696 | } |
| 697 | body, err := RequiredParam[string](args, "body") |
| 698 | if err != nil { |
| 699 | return utils.NewToolResultError(err.Error()), nil, nil |
| 700 | } |
| 701 | |
| 702 | // Get the discussion's node ID using its number |
| 703 | var q struct { |
| 704 | Repository struct { |
| 705 | Discussion struct { |
| 706 | ID githubv4.ID |
| 707 | } `graphql:"discussion(number: $discussionNumber)"` |
| 708 | } `graphql:"repository(owner: $owner, name: $repo)"` |
| 709 | } |
| 710 | vars := map[string]any{ |
| 711 | "owner": githubv4.String(owner), |
| 712 | "repo": githubv4.String(repo), |
| 713 | "discussionNumber": githubv4.Int(discussionNumber), // #nosec G115 - discussion numbers are always small positive integers |
| 714 | } |
| 715 | if err := client.Query(ctx, &q, vars); err != nil { |
| 716 | return utils.NewToolResultError(err.Error()), nil, nil |
| 717 | } |
| 718 | |
| 719 | input := githubv4.AddDiscussionCommentInput{ |
| 720 | DiscussionID: q.Repository.Discussion.ID, |
| 721 | Body: githubv4.String(body), |
| 722 | } |
| 723 | |
| 724 | var mutation struct { |
| 725 | AddDiscussionComment struct { |
| 726 | Comment struct { |
| 727 | ID githubv4.ID |
| 728 | URL githubv4.String `graphql:"url"` |
| 729 | } |
| 730 | } `graphql:"addDiscussionComment(input: $input)"` |
| 731 | } |
| 732 | |
| 733 | if err := client.Mutate(ctx, &mutation, input, nil); err != nil { |
| 734 | return utils.NewToolResultError(err.Error()), nil, nil |
| 735 | } |
| 736 | |
| 737 | comment := mutation.AddDiscussionComment.Comment |
| 738 | out, err := json.Marshal(MinimalResponse{ |
| 739 | ID: fmt.Sprintf("%v", comment.ID), |
| 740 | URL: string(comment.URL), |
| 741 | }) |
no test coverage detected