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

Function ResolveRef

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

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