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

Function resolveLatestRelease

internal/skills/discovery/discovery.go:342–365  ·  view source on GitHub ↗
(client *api.Client, host, owner, repo string)

Source from the content-addressed store, hash-verified

340func (e *noReleasesError) Error() string { return e.reason }
341
342func resolveLatestRelease(client *api.Client, host, owner, repo string) (*ResolvedRef, error) {
343 apiPath, err := safeurl.JoinPath("repos", owner, repo, "releases", "latest")
344 if err != nil {
345 return nil, err
346 }
347 var resp struct {
348 TagName string `json:"tag_name"`
349 }
350 if err := client.REST(host, "GET", apiPath.String(), nil, &resp); err != nil {
351 // A 404 means the repository has no releases. This is the
352 // only case where falling back to the default branch is safe.
353 // Any other HTTP error (403, 500, …) or network failure is
354 // returned as-is so ResolveRef surfaces it rather than
355 // silently falling back.
356 if isNotFound(err) {
357 return nil, &noReleasesError{reason: fmt.Sprintf("no releases found for %s/%s", owner, repo)}
358 }
359 return nil, fmt.Errorf("could not fetch latest release: %w", err)
360 }
361 if resp.TagName == "" {
362 return nil, &noReleasesError{reason: "latest release has no tag"}
363 }
364 return resolveTagRef(client, host, owner, repo, resp.TagName)
365}
366
367func resolveDefaultBranch(client *api.Client, host, owner, repo string) (*ResolvedRef, error) {
368 apiPath, err := safeurl.JoinPath("repos", owner, repo)

Callers 1

ResolveRefFunction · 0.85

Calls 6

JoinPathFunction · 0.92
isNotFoundFunction · 0.85
resolveTagRefFunction · 0.85
RESTMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected