MCPcopy
hub / github.com/cli/cli / AddComment

Method AddComment

pkg/cmd/discussion/client/client.go:1104–1159  ·  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

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected