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

Function resolveLatestRelease

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

Source from the content-addressed store, hash-verified

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