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

Method ListLabels

pkg/cmd/discussion/client/client.go:855–893  ·  view source on GitHub ↗

ListLabels fetches all labels for a repository, ordered alphabetically by name.

(repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

853
854// ListLabels fetches all labels for a repository, ordered alphabetically by name.
855func (c *discussionClient) ListLabels(repo ghrepo.Interface) ([]DiscussionLabel, error) {
856 var query struct {
857 Repository struct {
858 Labels struct {
859 Nodes []struct {
860 ID string
861 Name string
862 Color string
863 }
864 PageInfo struct {
865 HasNextPage bool
866 EndCursor string
867 }
868 } `graphql:"labels(first: 100, after: $endCursor, orderBy: {field: NAME, direction: ASC})"`
869 } `graphql:"repository(owner: $owner, name: $name)"`
870 }
871
872 variables := map[string]any{
873 "owner": githubv4.String(repo.RepoOwner()),
874 "name": githubv4.String(repo.RepoName()),
875 "endCursor": (*githubv4.String)(nil),
876 }
877
878 var labels []DiscussionLabel
879 for {
880 if err := c.gql.Query(repo.RepoHost(), "RepositoryLabelsForDiscussions", &query, variables); err != nil {
881 return nil, err
882 }
883 for _, n := range query.Repository.Labels.Nodes {
884 labels = append(labels, DiscussionLabel{ID: n.ID, Name: n.Name, Color: n.Color})
885 }
886 if !query.Repository.Labels.PageInfo.HasNextPage {
887 break
888 }
889 variables["endCursor"] = githubv4.String(query.Repository.Labels.PageInfo.EndCursor)
890 }
891
892 return labels, nil
893}
894
895// editDiscussionLabels adds and removes labels on a discussion. Removals are
896// applied before additions. Either slice may be nil or empty to skip that step.

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected