MCPcopy Index your code
hub / github.com/cli/cli / createRelease

Function createRelease

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

Source from the content-addressed store, hash-verified

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

Callers 1

createRunFunction · 0.85

Calls 9

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

Tested by

no test coverage detected