(httpClient *http.Client, repo ghrepo.Interface, params map[string]interface{})
| 175 | } |
| 176 | |
| 177 | func 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 | |
| 233 | func publishRelease(httpClient *http.Client, releaseURL safeurl.SafeURL, discussionCategory string, isLatest *bool) (*shared.Release, error) { |
| 234 | params := map[string]interface{}{"draft": false} |
no test coverage detected