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

Function RepoLabels

api/queries_repo.go:1421–1456  ·  view source on GitHub ↗

RepoLabels fetches all the labels in a repository

(client *Client, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

1419
1420// RepoLabels fetches all the labels in a repository
1421func RepoLabels(client *Client, repo ghrepo.Interface) ([]RepoLabel, error) {
1422 type responseData struct {
1423 Repository struct {
1424 Labels struct {
1425 Nodes []RepoLabel
1426 PageInfo struct {
1427 HasNextPage bool
1428 EndCursor string
1429 }
1430 } `graphql:"labels(first: 100, orderBy: {field: NAME, direction: ASC}, after: $endCursor)"`
1431 } `graphql:"repository(owner: $owner, name: $name)"`
1432 }
1433
1434 variables := map[string]any{
1435 "owner": githubv4.String(repo.RepoOwner()),
1436 "name": githubv4.String(repo.RepoName()),
1437 "endCursor": (*githubv4.String)(nil),
1438 }
1439
1440 var labels []RepoLabel
1441 for {
1442 var query responseData
1443 err := client.Query(repo.RepoHost(), "RepositoryLabelList", &query, variables)
1444 if err != nil {
1445 return nil, err
1446 }
1447
1448 labels = append(labels, query.Repository.Labels.Nodes...)
1449 if !query.Repository.Labels.PageInfo.HasNextPage {
1450 break
1451 }
1452 variables["endCursor"] = githubv4.String(query.Repository.Labels.PageInfo.EndCursor)
1453 }
1454
1455 return labels, nil
1456}
1457
1458type RepoMilestone struct {
1459 ID string

Callers 1

RepoMetadataFunction · 0.85

Calls 5

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

Tested by

no test coverage detected