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