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

Function ResolveRef

internal/skills/discovery/discovery.go:208–225  ·  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

206// ResolveRef determines the git ref to use for a given owner/repo.
207// Priority: explicit version > latest release tag > default branch.
208func ResolveRef(client *api.Client, host, owner, repo, version string) (*ResolvedRef, error) {
209 if version != "" {
210 return resolveExplicitRef(client, host, owner, repo, version)
211 }
212 ref, err := resolveLatestRelease(client, host, owner, repo)
213 if err == nil {
214 return ref, nil
215 }
216 // Only fall back to the default branch when the repository genuinely
217 // has no releases (404) or the latest release has no tag. Any other
218 // API error (403, 500, network failure, …) is surfaced immediately
219 // so it cannot silently mask problems and cause an unexpected ref to
220 // be used.
221 if _, ok := errors.AsType[*noReleasesError](err); !ok {
222 return nil, err
223 }
224 return resolveDefaultBranch(client, host, owner, repo)
225}
226
227// resolveExplicitRef resolves a user-supplied version string. It supports:
228// - 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