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

Function hasScript

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

Source from the content-addressed store, hash-verified

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