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

Function createRelease

pkg/cmd/release/create/http.go:141–181  ·  view source on GitHub ↗
(httpClient *http.Client, repo ghrepo.Interface, params map[string]any)

Source from the content-addressed store, hash-verified

139}
140
141func createRelease(httpClient *http.Client, repo ghrepo.Interface, params map[string]any) (*shared.Release, error) {
142 bodyBytes, err := json.Marshal(params)
143 if err != nil {
144 return nil, err
145 }
146
147 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "releases")
148 if err != nil {
149 return nil, err
150 }
151
152 // Check if we received a 404 while attempting to create a release without
153 // the workflow scope, and if so, return an error message that explains a possible
154 // solution to the user.
155 //
156 // If the same file (with both the same path and contents) exists
157 // on another branch in the repo, releases with workflow file changes can be
158 // created without the workflow scope. Otherwise, the workflow scope is
159 // required to create the release, but the API does not indicate this criteria
160 // beyond returning a 404.
161 //
162 // https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes
163 var newRelease shared.Release
164 // TODO(api-client-rollout)
165 // This line of code is part of a mechanical roll out of the api client.
166 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
167 err = api.NewClientFromHTTP(httpClient).REST(repo.RepoHost(), http.MethodPost, path.String(), bytes.NewBuffer(bodyBytes), &newRelease)
168 if err != nil {
169 var httpErr api.HTTPError
170 if errors.As(err, &httpErr) &&
171 httpErr.StatusCode == http.StatusNotFound &&
172 !tokenHasWorkflowScope(httpErr.Headers) {
173 normalizedHostname := ghauth.NormalizeHostname(httpErr.RequestURL.Hostname())
174 return nil, &errMissingRequiredWorkflowScope{
175 Hostname: normalizedHostname,
176 }
177 }
178 return nil, err
179 }
180 return &newRelease, nil
181}
182
183func publishRelease(httpClient *http.Client, host string, releaseURL safeurl.SafeURL, discussionCategory string, isLatest *bool) (*shared.Release, error) {
184 params := map[string]any{"draft": false}

Calls 8

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
tokenHasWorkflowScopeFunction · 0.85
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65