| 74 | } |
| 75 | |
| 76 | func generateReleaseNotes(httpClient *http.Client, repo ghrepo.Interface, tagName, target, previousTagName string) (*releaseNotes, error) { |
| 77 | params := map[string]interface{}{ |
| 78 | "tag_name": tagName, |
| 79 | } |
| 80 | if target != "" { |
| 81 | params["target_commitish"] = target |
| 82 | } |
| 83 | if previousTagName != "" { |
| 84 | params["previous_tag_name"] = previousTagName |
| 85 | } |
| 86 | |
| 87 | bodyBytes, err := json.Marshal(params) |
| 88 | if err != nil { |
| 89 | return nil, err |
| 90 | } |
| 91 | |
| 92 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "releases", "generate-notes") |
| 93 | if err != nil { |
| 94 | return nil, err |
| 95 | } |
| 96 | |
| 97 | var rn releaseNotes |
| 98 | // TODO(api-client-rollout) |
| 99 | // This line of code is part of a mechanical roll out of the api client. |
| 100 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 101 | err = api.NewClientFromHTTP(httpClient).REST(repo.RepoHost(), http.MethodPost, path.String(), bytes.NewBuffer(bodyBytes), &rn) |
| 102 | if err != nil { |
| 103 | var httpErr api.HTTPError |
| 104 | if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound { |
| 105 | return nil, notImplementedError |
| 106 | } |
| 107 | return nil, err |
| 108 | } |
| 109 | return &rn, nil |
| 110 | } |
| 111 | |
| 112 | func publishedReleaseExists(httpClient *http.Client, repo ghrepo.Interface, tagName string) (bool, error) { |
| 113 | url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "releases", "tags", tagName) |