MCPcopy
hub / github.com/cli/cli / GetByNumber

Method GetByNumber

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected