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

Function createRelease

pkg/cmd/release/create/http.go:177–231  ·  view source on GitHub ↗
(httpClient *http.Client, repo ghrepo.Interface, params map[string]interface{})

Source from the content-addressed store, hash-verified

175}
176
177func createRelease(httpClient *http.Client, repo ghrepo.Interface, params map[string]interface{}) (*shared.Release, error) {
178 bodyBytes, err := json.Marshal(params)
179 if err != nil {
180 return nil, err
181 }
182
183 url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "releases")
184 if err != nil {
185 return nil, err
186 }
187 req, err := http.NewRequest("POST", url.String(), bytes.NewBuffer(bodyBytes))
188 if err != nil {
189 return nil, err
190 }
191
192 req.Header.Set("Content-Type", "application/json; charset=utf-8")
193
194 resp, err := httpClient.Do(req)
195 if err != nil {
196 return nil, err
197 }
198 defer resp.Body.Close()
199
200 // Check if we received a 404 while attempting to create a release without
201 // the workflow scope, and if so, return an error message that explains a possible
202 // solution to the user.
203 //
204 // If the same file (with both the same path and contents) exists
205 // on another branch in the repo, releases with workflow file changes can be
206 // created without the workflow scope. Otherwise, the workflow scope is
207 // required to create the release, but the API does not indicate this criteria
208 // beyond returning a 404.
209 //
210 // https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes
211 if resp.StatusCode == http.StatusNotFound && !tokenHasWorkflowScope(resp) {
212 normalizedHostname := ghauth.NormalizeHostname(resp.Request.URL.Hostname())
213 return nil, &errMissingRequiredWorkflowScope{
214 Hostname: normalizedHostname,
215 }
216 }
217
218 success := resp.StatusCode >= 200 && resp.StatusCode < 300
219 if !success {
220 return nil, api.HandleHTTPError(resp)
221 }
222
223 b, err := io.ReadAll(resp.Body)
224 if err != nil {
225 return nil, err
226 }
227
228 var newRelease shared.Release
229 err = json.Unmarshal(b, &newRelease)
230 return &newRelease, err
231}
232
233func publishRelease(httpClient *http.Client, releaseURL safeurl.SafeURL, discussionCategory string, isLatest *bool) (*shared.Release, error) {
234 params := map[string]interface{}{"draft": false}

Callers 1

createRunFunction · 0.85

Calls 11

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

Tested by

no test coverage detected