| 13 | ) |
| 14 | |
| 15 | func repoExists(httpClient *http.Client, repo ghrepo.Interface) (bool, error) { |
| 16 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName()) |
| 17 | if err != nil { |
| 18 | return false, err |
| 19 | } |
| 20 | |
| 21 | // The response body is deliberately not read. Existence is decided by the status alone, |
| 22 | // so Request is used rather than REST, which would try to decode the body. |
| 23 | // TODO(api-client-rollout) |
| 24 | // This line of code is part of a mechanical roll out of the api client. |
| 25 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 26 | resp, err := api.NewClientFromHTTP(httpClient).Request(repo.RepoHost(), http.MethodGet, path.String(), nil) |
| 27 | if err != nil { |
| 28 | if httpErr, ok := errors.AsType[api.HTTPError](err); ok && httpErr.StatusCode == http.StatusNotFound { |
| 29 | return false, nil |
| 30 | } |
| 31 | return false, err |
| 32 | } |
| 33 | defer resp.Body.Close() |
| 34 | |
| 35 | // Only 200 means the repository exists. Any other success status is unexpected here and is |
| 36 | // reported as an error rather than being taken as existence. |
| 37 | if resp.StatusCode != http.StatusOK { |
| 38 | return false, api.UnexpectedStatusError(resp) |
| 39 | } |
| 40 | |
| 41 | return true, nil |
| 42 | } |
| 43 | |
| 44 | func hasScript(httpClient *http.Client, repo ghrepo.Interface) (bool, error) { |
| 45 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "contents", repo.RepoName()) |