isNewRelease checks if there are new commits since the latest release.
(httpClient *http.Client, repo ghrepo.Interface)
| 237 | |
| 238 | // isNewRelease checks if there are new commits since the latest release. |
| 239 | func isNewRelease(httpClient *http.Client, repo ghrepo.Interface) (bool, error) { |
| 240 | ctx := context.Background() |
| 241 | release, err := shared.FetchLatestRelease(ctx, httpClient, repo) |
| 242 | if err != nil { |
| 243 | if errors.Is(err, shared.ErrReleaseNotFound) { |
| 244 | return true, nil |
| 245 | } else { |
| 246 | return false, err |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | tagName := release.TagName |
| 251 | u, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "compare", tagName+"...HEAD") |
| 252 | if err != nil { |
| 253 | return false, err |
| 254 | } |
| 255 | u.SetQuery("per_page", "1") |
| 256 | |
| 257 | var comparisonStatus struct { |
| 258 | Status string `json:"status"` |
| 259 | } |
| 260 | |
| 261 | apiClient := api.NewClientFromHTTP(httpClient) |
| 262 | if err := apiClient.REST(repo.RepoHost(), "GET", u.String(), nil, &comparisonStatus); err != nil { |
| 263 | return false, err |
| 264 | } |
| 265 | |
| 266 | isNew := comparisonStatus.Status == "ahead" |
| 267 | return isNew, nil |
| 268 | } |
no test coverage detected