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