isNewRelease checks if there are new commits since the latest release.
(httpClient *http.Client, repo ghrepo.Interface)
| 313 | |
| 314 | // isNewRelease checks if there are new commits since the latest release. |
| 315 | func isNewRelease(httpClient *http.Client, repo ghrepo.Interface) (bool, error) { |
| 316 | ctx := context.Background() |
| 317 | release, err := shared.FetchLatestRelease(ctx, httpClient, repo) |
| 318 | if err != nil { |
| 319 | if errors.Is(err, shared.ErrReleaseNotFound) { |
| 320 | return true, nil |
| 321 | } else { |
| 322 | return false, err |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | tagName := release.TagName |
| 327 | u, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "compare", tagName+"...HEAD") |
| 328 | if err != nil { |
| 329 | return false, err |
| 330 | } |
| 331 | u.SetQuery("per_page", "1") |
| 332 | |
| 333 | var comparisonStatus struct { |
| 334 | Status string `json:"status"` |
| 335 | } |
| 336 | |
| 337 | apiClient := api.NewClientFromHTTP(httpClient) |
| 338 | if err := apiClient.REST(repo.RepoHost(), "GET", u.String(), nil, &comparisonStatus); err != nil { |
| 339 | return false, err |
| 340 | } |
| 341 | |
| 342 | isNew := comparisonStatus.Status == "ahead" |
| 343 | return isNew, nil |
| 344 | } |
no test coverage detected