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)
| 1633 | // This is similar logic to RepoNetwork, but only fetches databaseId and does not |
| 1634 | // discover parent repositories. |
| 1635 | func GetRepoIDs(client *Client, host string, repositories []ghrepo.Interface) ([]int64, error) { |
| 1636 | queries := make([]string, 0, len(repositories)) |
| 1637 | for i, repo := range repositories { |
| 1638 | queries = append(queries, fmt.Sprintf(` |
| 1639 | repo_%03d: repository(owner: %q, name: %q) { |
| 1640 | databaseId |
| 1641 | } |
| 1642 | `, i, repo.RepoOwner(), repo.RepoName())) |
| 1643 | } |
| 1644 | |
| 1645 | query := fmt.Sprintf(`query MapRepositoryNames { %s }`, strings.Join(queries, "")) |
| 1646 | |
| 1647 | graphqlResult := make(map[string]*struct { |
| 1648 | DatabaseID int64 `json:"databaseId"` |
| 1649 | }) |
| 1650 | |
| 1651 | if err := client.GraphQL(host, query, nil, &graphqlResult); err != nil { |
| 1652 | return nil, fmt.Errorf("failed to look up repositories: %w", err) |
| 1653 | } |
| 1654 | |
| 1655 | repoKeys := make([]string, 0, len(repositories)) |
| 1656 | for k := range graphqlResult { |
| 1657 | repoKeys = append(repoKeys, k) |
| 1658 | } |
| 1659 | sort.Strings(repoKeys) |
| 1660 | |
| 1661 | result := make([]int64, len(repositories)) |
| 1662 | for i, k := range repoKeys { |
| 1663 | result[i] = graphqlResult[k].DatabaseID |
| 1664 | } |
| 1665 | return result, nil |
| 1666 | } |
| 1667 | |
| 1668 | func RepoExists(client *Client, repo ghrepo.Interface) (bool, error) { |
| 1669 | path := fmt.Sprintf("%srepos/%s/%s", ghinstance.RESTPrefix(repo.RepoHost()), repo.RepoOwner(), repo.RepoName()) |