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)
| 267 | // resolveTagRef looks up a tag by short name and returns a fully qualified ref. |
| 268 | // For annotated tags, the tag object is dereferenced to obtain the commit SHA. |
| 269 | func resolveTagRef(client *api.Client, host, owner, repo, tag string) (*ResolvedRef, error) { |
| 270 | tagPath := fmt.Sprintf("repos/%s/%s/git/ref/tags/%s", url.PathEscape(owner), url.PathEscape(repo), url.PathEscape(tag)) |
| 271 | var refResp struct { |
| 272 | Object struct { |
| 273 | SHA string `json:"sha"` |
| 274 | Type string `json:"type"` |
| 275 | } `json:"object"` |
| 276 | } |
| 277 | if err := client.REST(host, "GET", tagPath, nil, &refResp); err != nil { |
| 278 | return nil, fmt.Errorf("tag %q not found in %s/%s: %w", tag, owner, repo, err) |
| 279 | } |
| 280 | sha := refResp.Object.SHA |
| 281 | if refResp.Object.Type == "tag" { |
| 282 | derefPath := fmt.Sprintf("repos/%s/%s/git/tags/%s", url.PathEscape(owner), url.PathEscape(repo), url.PathEscape(sha)) |
| 283 | var tagResp struct { |
| 284 | Object struct { |
| 285 | SHA string `json:"sha"` |
| 286 | } `json:"object"` |
| 287 | } |
| 288 | if err := client.REST(host, "GET", derefPath, nil, &tagResp); err != nil { |
| 289 | return nil, fmt.Errorf("could not dereference annotated tag %q: %w", tag, err) |
| 290 | } |
| 291 | sha = tagResp.Object.SHA |
| 292 | } |
| 293 | return &ResolvedRef{Ref: "refs/tags/" + tag, SHA: sha}, nil |
| 294 | } |
| 295 | |
| 296 | // resolveBranchRef looks up a branch by short name and returns a fully qualified ref. |
| 297 | func resolveBranchRef(client *api.Client, host, owner, repo, branch string) (*ResolvedRef, error) { |
no test coverage detected