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