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

Method GetWithComments

pkg/cmd/discussion/client/client.go:535–635  ·  view source on GitHub ↗
(repo ghrepo.Interface, number int32, limit int, after string, newest bool)

Source from the content-addressed store, hash-verified

533}
534
535func (c *discussionClient) GetWithComments(repo ghrepo.Interface, number int32, limit int, after string, newest bool) (*Discussion, error) {
536 meta, err := c.getRepositoryMeta(repo)
537 if err != nil {
538 return nil, err
539 }
540 if !meta.HasDiscussionsEnabled {
541 return nil, fmt.Errorf("the '%s/%s' repository has discussions disabled", repo.RepoOwner(), repo.RepoName())
542 }
543
544 var query struct {
545 Repository struct {
546 Discussion struct {
547 discussionListNode
548 Comments struct {
549 TotalCount int
550 PageInfo struct {
551 EndCursor string
552 HasNextPage bool
553 StartCursor string
554 HasPreviousPage bool
555 }
556 Nodes []discussionCommentNode
557 } `graphql:"comments(first: $first, last: $last, after: $after, before: $before)"`
558 } `graphql:"discussion(number: $number)"`
559 } `graphql:"repository(owner: $owner, name: $name)"`
560 }
561
562 variables := map[string]any{
563 "owner": githubv4.String(repo.RepoOwner()),
564 "name": githubv4.String(repo.RepoName()),
565 "number": githubv4.Int(number),
566 "first": (*githubv4.Int)(nil),
567 "last": (*githubv4.Int)(nil),
568 "after": (*githubv4.String)(nil),
569 "before": (*githubv4.String)(nil),
570 }
571
572 if newest {
573 variables["last"] = githubv4.Int(min(limit, maxPageSize))
574 if after != "" {
575 variables["before"] = githubv4.String(after)
576 }
577 } else {
578 variables["first"] = githubv4.Int(min(limit, maxPageSize))
579 if after != "" {
580 variables["after"] = githubv4.String(after)
581 }
582 }
583
584 if err := c.gql.Query(repo.RepoHost(), "DiscussionWithComments", &query, variables); err != nil {
585 return nil, err
586 }
587
588 src := query.Repository.Discussion
589
590 d := mapDiscussionFromListNode(src.discussionListNode)
591
592 for _, rg := range src.ReactionGroups {

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected