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

Function hasScript

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

Source from the content-addressed store, hash-verified

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())
46 if err != nil {
47 return false, err
48 }
49
50 // The response body is not decoded, because a script is considered present for any
51 // successful response regardless of the content type reported.
52 // TODO(api-client-rollout)
53 // This line of code is part of a mechanical roll out of the api client.
54 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
55 err = api.NewClientFromHTTP(httpClient).REST(repo.RepoHost(), http.MethodGet, path.String(), nil, nil)
56 if err != nil {
57 var httpErr api.HTTPError
58 if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound {
59 return false, nil
60 }
61 return false, err
62 }
63
64 return true, nil
65}
66
67type releaseAsset struct {
68 Name string

Callers 2

InstallMethod · 0.85
TestHasScriptFunction · 0.85

Calls 7

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by 1

TestHasScriptFunction · 0.68