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

Function repoExists

pkg/cmd/extension/http.go:15–42  ·  view source on GitHub ↗
(httpClient *http.Client, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

13)
14
15func 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
44func hasScript(httpClient *http.Client, repo ghrepo.Interface) (bool, error) {
45 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "contents", repo.RepoName())

Callers 2

InstallMethod · 0.85
TestRepoExistsFunction · 0.85

Calls 9

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
UnexpectedStatusErrorFunction · 0.92
RequestMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestRepoExistsFunction · 0.68