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

Function resolveTagRef

internal/skills/discovery/discovery.go:276–307  ·  view source on GitHub ↗

resolveTagRef looks up a tag by short name and returns a fully qualified ref. For annotated tags, the tag object is dereferenced to obtain the commit SHA.

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

Source from the content-addressed store, hash-verified

274// resolveTagRef looks up a tag by short name and returns a fully qualified ref.
275// For annotated tags, the tag object is dereferenced to obtain the commit SHA.
276func resolveTagRef(client *api.Client, host, owner, repo, tag string) (*ResolvedRef, error) {
277 tagPath, err := safeurl.JoinPath("repos", owner, repo, "git", "ref", fmt.Sprintf("tags/%s", tag))
278 if err != nil {
279 return nil, err
280 }
281 var refResp struct {
282 Object struct {
283 SHA string `json:"sha"`
284 Type string `json:"type"`
285 } `json:"object"`
286 }
287 if err := client.REST(host, "GET", tagPath.String(), nil, &refResp); err != nil {
288 return nil, fmt.Errorf("tag %q not found in %s/%s: %w", tag, owner, repo, err)
289 }
290 sha := refResp.Object.SHA
291 if refResp.Object.Type == "tag" {
292 derefPath, err := safeurl.JoinPath("repos", owner, repo, "git", "tags", sha)
293 if err != nil {
294 return nil, err
295 }
296 var tagResp struct {
297 Object struct {
298 SHA string `json:"sha"`
299 } `json:"object"`
300 }
301 if err := client.REST(host, "GET", derefPath.String(), nil, &tagResp); err != nil {
302 return nil, fmt.Errorf("could not dereference annotated tag %q: %w", tag, err)
303 }
304 sha = tagResp.Object.SHA
305 }
306 return &ResolvedRef{Ref: "refs/tags/" + tag, SHA: sha}, nil
307}
308
309// resolveBranchRef looks up a branch by short name and returns a fully qualified ref.
310func resolveBranchRef(client *api.Client, host, owner, repo, branch string) (*ResolvedRef, error) {

Callers 2

resolveExplicitRefFunction · 0.85
resolveLatestReleaseFunction · 0.85

Calls 4

JoinPathFunction · 0.92
RESTMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected