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

Method ListCategories

pkg/cmd/discussion/client/client.go:778–819  ·  view source on GitHub ↗
(repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

776}
777
778func (c *discussionClient) ListCategories(repo ghrepo.Interface) ([]DiscussionCategory, error) {
779 var query struct {
780 Repository struct {
781 HasDiscussionsEnabled bool
782 DiscussionCategories struct {
783 Nodes []struct {
784 ID string
785 Name string
786 Slug string
787 Emoji string
788 IsAnswerable bool
789 }
790 } `graphql:"discussionCategories(first: 100)"`
791 } `graphql:"repository(owner: $owner, name: $name)"`
792 }
793
794 variables := map[string]any{
795 "owner": githubv4.String(repo.RepoOwner()),
796 "name": githubv4.String(repo.RepoName()),
797 }
798
799 if err := c.gql.Query(repo.RepoHost(), "DiscussionCategoryList", &query, variables); err != nil {
800 return nil, err
801 }
802
803 if !query.Repository.HasDiscussionsEnabled {
804 return nil, fmt.Errorf("the '%s/%s' repository has discussions disabled", repo.RepoOwner(), repo.RepoName())
805 }
806
807 categories := make([]DiscussionCategory, len(query.Repository.DiscussionCategories.Nodes))
808 for i, n := range query.Repository.DiscussionCategories.Nodes {
809 categories[i] = DiscussionCategory{
810 ID: n.ID,
811 Name: n.Name,
812 Slug: n.Slug,
813 Emoji: n.Emoji,
814 IsAnswerable: n.IsAnswerable,
815 }
816 }
817
818 return categories, nil
819}
820
821// repositoryMeta holds the node ID, database ID, and feature flags fetched for a repository.
822type repositoryMeta struct {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected