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

Method GetByNumber

pkg/cmd/discussion/client/client.go:401–442  ·  view source on GitHub ↗
(repo ghrepo.Interface, number int32)

Source from the content-addressed store, hash-verified

399}
400
401func (c *discussionClient) GetByNumber(repo ghrepo.Interface, number int32) (*Discussion, error) {
402 meta, err := c.getRepositoryMeta(repo)
403 if err != nil {
404 return nil, err
405 }
406 if !meta.HasDiscussionsEnabled {
407 return nil, fmt.Errorf("the '%s/%s' repository has discussions disabled", repo.RepoOwner(), repo.RepoName())
408 }
409
410 var query struct {
411 Repository struct {
412 Discussion struct {
413 discussionListNode
414 Comments struct {
415 TotalCount int
416 }
417 } `graphql:"discussion(number: $number)"`
418 } `graphql:"repository(owner: $owner, name: $name)"`
419 }
420
421 variables := map[string]any{
422 "owner": githubv4.String(repo.RepoOwner()),
423 "name": githubv4.String(repo.RepoName()),
424 "number": githubv4.Int(number),
425 }
426
427 if err := c.gql.Query(repo.RepoHost(), "DiscussionMinimal", &query, variables); err != nil {
428 return nil, err
429 }
430
431 d := mapDiscussionFromListNode(query.Repository.Discussion.discussionListNode)
432 d.Comments = DiscussionCommentList{TotalCount: query.Repository.Discussion.Comments.TotalCount}
433
434 for _, rg := range query.Repository.Discussion.ReactionGroups {
435 d.ReactionGroups = append(d.ReactionGroups, ReactionGroup{
436 Content: rg.Content,
437 TotalCount: rg.Users.TotalCount,
438 })
439 }
440
441 return &d, nil
442}
443
444// discussionReplyNode is the GraphQL response shape for a reply to a discussion comment.
445type discussionReplyNode struct {

Callers

nothing calls this directly

Calls 8

getRepositoryMetaMethod · 0.95
ErrorfMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
StringMethod · 0.65
QueryMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected