GetComment fetches a single discussion comment by node ID.
(host string, commentID string)
| 1228 | |
| 1229 | // GetComment fetches a single discussion comment by node ID. |
| 1230 | func (c *discussionClient) GetComment(host string, commentID string) (*DiscussionComment, error) { |
| 1231 | var query struct { |
| 1232 | Node struct { |
| 1233 | Typename string `graphql:"__typename"` |
| 1234 | DiscussionComment struct { |
| 1235 | ID string |
| 1236 | URL string `graphql:"url"` |
| 1237 | Author actorNode |
| 1238 | Body string |
| 1239 | CreatedAt time.Time |
| 1240 | IsAnswer bool |
| 1241 | UpvoteCount int |
| 1242 | Discussion struct { |
| 1243 | ID string |
| 1244 | } |
| 1245 | ReactionGroups []struct { |
| 1246 | Content string |
| 1247 | Users struct { |
| 1248 | TotalCount int |
| 1249 | } |
| 1250 | } `graphql:"reactionGroups"` |
| 1251 | } `graphql:"... on DiscussionComment"` |
| 1252 | } `graphql:"node(id: $id)"` |
| 1253 | } |
| 1254 | |
| 1255 | variables := map[string]any{ |
| 1256 | "id": githubv4.ID(commentID), |
| 1257 | } |
| 1258 | |
| 1259 | if err := c.gql.Query(host, "GetDiscussionComment", &query, variables); err != nil { |
| 1260 | return nil, err |
| 1261 | } |
| 1262 | |
| 1263 | if query.Node.Typename != "DiscussionComment" { |
| 1264 | return nil, fmt.Errorf("node %s is not a discussion comment (got %s)", commentID, query.Node.Typename) |
| 1265 | } |
| 1266 | |
| 1267 | src := query.Node.DiscussionComment |
| 1268 | comment := &DiscussionComment{ |
| 1269 | ID: src.ID, |
| 1270 | URL: src.URL, |
| 1271 | DiscussionID: src.Discussion.ID, |
| 1272 | Author: mapActorFromListNode(src.Author), |
| 1273 | Body: src.Body, |
| 1274 | CreatedAt: src.CreatedAt, |
| 1275 | IsAnswer: src.IsAnswer, |
| 1276 | UpvoteCount: src.UpvoteCount, |
| 1277 | } |
| 1278 | for _, rg := range src.ReactionGroups { |
| 1279 | comment.ReactionGroups = append(comment.ReactionGroups, ReactionGroup{ |
| 1280 | Content: rg.Content, |
| 1281 | TotalCount: rg.Users.TotalCount, |
| 1282 | }) |
| 1283 | } |
| 1284 | return comment, nil |
| 1285 | } |
| 1286 | |
| 1287 | // ResolveCommentNodeID constructs a discussion comment node ID from a |
nothing calls this directly
no test coverage detected