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

Function ResolveRef

internal/skills/discovery/discovery.go:237–254  ·  view source on GitHub ↗

ResolveRef determines the git ref to use for a given owner/repo. Priority: explicit version > latest release tag > default branch.

(client *api.Client, host, owner, repo, version string)

Source from the content-addressed store, hash-verified

235// ResolveRef determines the git ref to use for a given owner/repo.
236// Priority: explicit version > latest release tag > default branch.
237func ResolveRef(client *api.Client, host, owner, repo, version string) (*ResolvedRef, error) {
238 if version != "" {
239 return resolveExplicitRef(client, host, owner, repo, version)
240 }
241 ref, err := resolveLatestRelease(client, host, owner, repo)
242 if err == nil {
243 return ref, nil
244 }
245 // Only fall back to the default branch when the repository genuinely
246 // has no releases (404) or the latest release has no tag. Any other
247 // API error (403, 500, network failure, …) is surfaced immediately
248 // so it cannot silently mask problems and cause an unexpected ref to
249 // be used.
250 if _, ok := errors.AsType[*noReleasesError](err); !ok {
251 return nil, err
252 }
253 return resolveDefaultBranch(client, host, owner, repo)
254}
255
256// resolveExplicitRef resolves a user-supplied version string. It supports:
257// - fully qualified refs: "refs/tags/v1.0" or "refs/heads/main"

Callers 4

updateRunFunction · 0.92
resolveVersionFunction · 0.92
previewRunFunction · 0.92
TestResolveRefFunction · 0.85

Calls 3

resolveExplicitRefFunction · 0.85
resolveLatestReleaseFunction · 0.85
resolveDefaultBranchFunction · 0.85

Tested by 1

TestResolveRefFunction · 0.68