(httpClient *http.Client, repo ghrepo.Interface, tagName string)
| 108 | } |
| 109 | |
| 110 | func publishedReleaseExists(httpClient *http.Client, repo ghrepo.Interface, tagName string) (bool, error) { |
| 111 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "releases", "tags", tagName) |
| 112 | if err != nil { |
| 113 | return false, err |
| 114 | } |
| 115 | |
| 116 | // A HEAD response has no body, so Request is used rather than REST, which would try to |
| 117 | // decode one. |
| 118 | // TODO(api-client-rollout) |
| 119 | // This line of code is part of a mechanical roll out of the api client. |
| 120 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 121 | resp, err := api.NewClientFromHTTP(httpClient).Request(repo.RepoHost(), http.MethodHead, path.String(), nil) |
| 122 | if err != nil { |
| 123 | var httpErr api.HTTPError |
| 124 | if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound { |
| 125 | return false, nil |
| 126 | } |
| 127 | return false, err |
| 128 | } |
| 129 | if resp.Body != nil { |
| 130 | defer resp.Body.Close() |
| 131 | } |
| 132 | |
| 133 | if resp.StatusCode != http.StatusOK { |
| 134 | return false, api.UnexpectedStatusError(resp) |
| 135 | } |
| 136 | |
| 137 | return true, nil |
| 138 | } |
| 139 | |
| 140 | func createRelease(httpClient *http.Client, repo ghrepo.Interface, params map[string]any) (*shared.Release, error) { |
| 141 | bodyBytes, err := json.Marshal(params) |
no test coverage detected