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

Function publishedReleaseExists

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

Source from the content-addressed store, hash-verified

110}
111
112func publishedReleaseExists(httpClient *http.Client, repo ghrepo.Interface, tagName string) (bool, error) {
113 url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "releases", "tags", tagName)
114 if err != nil {
115 return false, err
116 }
117 req, err := http.NewRequest("HEAD", url.String(), nil)
118 if err != nil {
119 return false, err
120 }
121
122 // TODO(api-client-rollout)
123 // This has been deferred from moving to api.Client due to HEAD responses having no body while REST decodes non-204/205 2xx responses as JSON.
124 resp, err := httpClient.Do(req)
125 if err != nil {
126 return false, err
127 }
128 if resp.Body != nil {
129 defer resp.Body.Close()
130 }
131
132 if resp.StatusCode == 200 {
133 return true, nil
134 } else if resp.StatusCode == 404 {
135 return false, nil
136 } else {
137 return false, api.HandleHTTPError(resp)
138 }
139}
140
141func createRelease(httpClient *http.Client, repo ghrepo.Interface, params map[string]interface{}) (*shared.Release, error) {
142 bodyBytes, err := json.Marshal(params)

Callers 1

createRunFunction · 0.85

Calls 9

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
StringMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected