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

Function GetRepoIDs

api/queries_repo.go:1644–1675  ·  view source on GitHub ↗

MapReposToIDs retrieves a set of IDs for the given set of repositories. This is similar logic to RepoNetwork, but only fetches databaseId and does not discover parent repositories.

(client *Client, host string, repositories []ghrepo.Interface)

Source from the content-addressed store, hash-verified

1642// This is similar logic to RepoNetwork, but only fetches databaseId and does not
1643// discover parent repositories.
1644func GetRepoIDs(client *Client, host string, repositories []ghrepo.Interface) ([]int64, error) {
1645 queries := make([]string, 0, len(repositories))
1646 for i, repo := range repositories {
1647 queries = append(queries, fmt.Sprintf(`
1648 repo_%03d: repository(owner: %q, name: %q) {
1649 databaseId
1650 }
1651 `, i, repo.RepoOwner(), repo.RepoName()))
1652 }
1653
1654 query := fmt.Sprintf(`query MapRepositoryNames { %s }`, strings.Join(queries, ""))
1655
1656 graphqlResult := make(map[string]*struct {
1657 DatabaseID int64 `json:"databaseId"`
1658 })
1659
1660 if err := client.GraphQL(host, query, nil, &graphqlResult); err != nil {
1661 return nil, fmt.Errorf("failed to look up repositories: %w", err)
1662 }
1663
1664 repoKeys := make([]string, 0, len(repositories))
1665 for k := range graphqlResult {
1666 repoKeys = append(repoKeys, k)
1667 }
1668 sort.Strings(repoKeys)
1669
1670 result := make([]int64, len(repositories))
1671 for i, k := range repoKeys {
1672 result[i] = graphqlResult[k].DatabaseID
1673 }
1674 return result, nil
1675}
1676
1677func RepoExists(client *Client, repo ghrepo.Interface) (bool, error) {
1678 u, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName())

Callers 3

getRepoIdsFunction · 0.92
setVariableFunction · 0.92
mapRepoNamesToIDsFunction · 0.92

Calls 5

JoinMethod · 0.80
GraphQLMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected