(httpClient *http.Client, repo ghrepo.Interface, tagName, target, previousTagName string)
| 91 | } |
| 92 | |
| 93 | func generateReleaseNotes(httpClient *http.Client, repo ghrepo.Interface, tagName, target, previousTagName string) (*releaseNotes, error) { |
| 94 | params := map[string]interface{}{ |
| 95 | "tag_name": tagName, |
| 96 | } |
| 97 | if target != "" { |
| 98 | params["target_commitish"] = target |
| 99 | } |
| 100 | if previousTagName != "" { |
| 101 | params["previous_tag_name"] = previousTagName |
| 102 | } |
| 103 | |
| 104 | bodyBytes, err := json.Marshal(params) |
| 105 | if err != nil { |
| 106 | return nil, err |
| 107 | } |
| 108 | |
| 109 | path := fmt.Sprintf("repos/%s/%s/releases/generate-notes", repo.RepoOwner(), repo.RepoName()) |
| 110 | url := ghinstance.RESTPrefix(repo.RepoHost()) + path |
| 111 | req, err := http.NewRequest("POST", url, bytes.NewBuffer(bodyBytes)) |
| 112 | if err != nil { |
| 113 | return nil, err |
| 114 | } |
| 115 | |
| 116 | req.Header.Set("Accept", "application/vnd.github.v3+json") |
| 117 | req.Header.Set("Content-Type", "application/json; charset=utf-8") |
| 118 | |
| 119 | resp, err := httpClient.Do(req) |
| 120 | if err != nil { |
| 121 | return nil, err |
| 122 | } |
| 123 | defer resp.Body.Close() |
| 124 | |
| 125 | if resp.StatusCode == 404 { |
| 126 | return nil, notImplementedError |
| 127 | } |
| 128 | |
| 129 | success := resp.StatusCode >= 200 && resp.StatusCode < 300 |
| 130 | if !success { |
| 131 | return nil, api.HandleHTTPError(resp) |
| 132 | } |
| 133 | |
| 134 | b, err := io.ReadAll(resp.Body) |
| 135 | if err != nil { |
| 136 | return nil, err |
| 137 | } |
| 138 | |
| 139 | var rn releaseNotes |
| 140 | err = json.Unmarshal(b, &rn) |
| 141 | return &rn, err |
| 142 | } |
| 143 | |
| 144 | func publishedReleaseExists(httpClient *http.Client, repo ghrepo.Interface, tagName string) (bool, error) { |
| 145 | path := fmt.Sprintf("repos/%s/%s/releases/tags/%s", repo.RepoOwner(), repo.RepoName(), url.PathEscape(tagName)) |
no test coverage detected