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)
| 303 | // resolveTagRef looks up a tag by short name and returns a fully qualified ref. |
| 304 | // For annotated tags, the tag object is dereferenced to obtain the commit SHA. |
| 305 | func resolveTagRef(client *api.Client, host, owner, repo, tag string) (*ResolvedRef, error) { |
| 306 | tagPath, err := safeurl.JoinPath("repos", owner, repo, "git", "ref", fmt.Sprintf("tags/%s", tag)) |
| 307 | if err != nil { |
| 308 | return nil, err |
| 309 | } |
| 310 | var refResp struct { |
| 311 | Object struct { |
| 312 | SHA string `json:"sha"` |
| 313 | Type string `json:"type"` |
| 314 | } `json:"object"` |
| 315 | } |
| 316 | if err := client.REST(host, "GET", tagPath.String(), nil, &refResp); err != nil { |
| 317 | return nil, fmt.Errorf("tag %q not found in %s/%s: %w", tag, owner, repo, err) |
| 318 | } |
| 319 | sha := refResp.Object.SHA |
| 320 | if refResp.Object.Type == "tag" { |
| 321 | derefPath, err := safeurl.JoinPath("repos", owner, repo, "git", "tags", sha) |
| 322 | if err != nil { |
| 323 | return nil, err |
| 324 | } |
| 325 | var tagResp struct { |
| 326 | Object struct { |
| 327 | SHA string `json:"sha"` |
| 328 | } `json:"object"` |
| 329 | } |
| 330 | if err := client.REST(host, "GET", derefPath.String(), nil, &tagResp); err != nil { |
| 331 | return nil, fmt.Errorf("could not dereference annotated tag %q: %w", tag, err) |
| 332 | } |
| 333 | sha = tagResp.Object.SHA |
| 334 | } |
| 335 | return &ResolvedRef{Ref: "refs/tags/" + tag, SHA: sha}, nil |
| 336 | } |
| 337 | |
| 338 | // resolveBranchRef looks up a branch by short name and returns a fully qualified ref. |
| 339 | func resolveBranchRef(client *api.Client, host, owner, repo, branch string) (*ResolvedRef, error) { |
no test coverage detected