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

Function isNewRelease

pkg/cmd/release/create/http.go:239–268  ·  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

237
238// isNewRelease checks if there are new commits since the latest release.
239func 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}

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