MCPcopy Create free account
hub / github.com/cli/cli / AddComment

Method AddComment

pkg/cmd/discussion/client/client.go:1101–1156  ·  view source on GitHub ↗

AddComment adds a comment to a discussion. If replyToID is non-empty, the comment is created as a reply to that comment.

(repo ghrepo.Interface, discussionID, body, replyToID string)

Source from the content-addressed store, hash-verified

1099// AddComment adds a comment to a discussion. If replyToID is non-empty, the
1100// comment is created as a reply to that comment.
1101func (c *discussionClient) AddComment(repo ghrepo.Interface, discussionID, body, replyToID string) (*DiscussionComment, error) {
1102 var mutation struct {
1103 AddDiscussionComment struct {
1104 Comment struct {
1105 ID string
1106 URL string `graphql:"url"`
1107 Author actorNode
1108 Body string
1109 CreatedAt time.Time
1110 IsAnswer bool
1111 UpvoteCount int
1112 ReactionGroups []struct {
1113 Content string
1114 Users struct {
1115 TotalCount int
1116 }
1117 } `graphql:"reactionGroups"`
1118 }
1119 } `graphql:"addDiscussionComment(input: $input)"`
1120 }
1121
1122 input := githubv4.AddDiscussionCommentInput{
1123 DiscussionID: githubv4.ID(discussionID),
1124 Body: githubv4.String(body),
1125 }
1126 if replyToID != "" {
1127 id := githubv4.ID(replyToID)
1128 input.ReplyToID = &id
1129 }
1130
1131 variables := map[string]any{
1132 "input": input,
1133 }
1134
1135 if err := c.gql.Mutate(repo.RepoHost(), "AddDiscussionComment", &mutation, variables); err != nil {
1136 return nil, err
1137 }
1138
1139 src := mutation.AddDiscussionComment.Comment
1140 comment := &DiscussionComment{
1141 ID: src.ID,
1142 URL: src.URL,
1143 Author: mapActorFromListNode(src.Author),
1144 Body: src.Body,
1145 CreatedAt: src.CreatedAt,
1146 IsAnswer: src.IsAnswer,
1147 UpvoteCount: src.UpvoteCount,
1148 }
1149 for _, rg := range src.ReactionGroups {
1150 comment.ReactionGroups = append(comment.ReactionGroups, ReactionGroup{
1151 Content: rg.Content,
1152 TotalCount: rg.Users.TotalCount,
1153 })
1154 }
1155 return comment, nil
1156}
1157
1158// UpdateComment updates the body of an existing discussion comment or reply.

Callers

nothing calls this directly

Calls 5

mapActorFromListNodeFunction · 0.85
IDMethod · 0.65
StringMethod · 0.65
MutateMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected