MCPcopy
hub / github.com/cli/cli / ListLabels

Method ListLabels

pkg/cmd/discussion/client/client.go:858–896  ·  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

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected