MCPcopy Create free account
hub / github.com/cli/cli / isNewRelease

Function isNewRelease

pkg/cmd/release/create/http.go:315–344  ·  view source on GitHub ↗

isNewRelease checks if there are new commits since the latest release.

(httpClient *http.Client, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

313
314// isNewRelease checks if there are new commits since the latest release.
315func 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}

Callers 1

createRunFunction · 0.85

Calls 9

FetchLatestReleaseFunction · 0.92
JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
SetQueryMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected