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

Function publishedReleaseExists

pkg/cmd/release/create/http.go:110–138  ·  view source on GitHub ↗
(httpClient *http.Client, repo ghrepo.Interface, tagName string)

Source from the content-addressed store, hash-verified

108}
109
110func publishedReleaseExists(httpClient *http.Client, repo ghrepo.Interface, tagName string) (bool, error) {
111 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "releases", "tags", tagName)
112 if err != nil {
113 return false, err
114 }
115
116 // A HEAD response has no body, so Request is used rather than REST, which would try to
117 // decode one.
118 // TODO(api-client-rollout)
119 // This line of code is part of a mechanical roll out of the api client.
120 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
121 resp, err := api.NewClientFromHTTP(httpClient).Request(repo.RepoHost(), http.MethodHead, path.String(), nil)
122 if err != nil {
123 var httpErr api.HTTPError
124 if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound {
125 return false, nil
126 }
127 return false, err
128 }
129 if resp.Body != nil {
130 defer resp.Body.Close()
131 }
132
133 if resp.StatusCode != http.StatusOK {
134 return false, api.UnexpectedStatusError(resp)
135 }
136
137 return true, nil
138}
139
140func createRelease(httpClient *http.Client, repo ghrepo.Interface, params map[string]any) (*shared.Release, error) {
141 bodyBytes, err := json.Marshal(params)

Callers 1

createRunFunction · 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

no test coverage detected