resolveBranchRef looks up a branch by short name and returns a fully qualified ref.
(client *api.Client, host, owner, repo, branch string)
| 308 | |
| 309 | // resolveBranchRef looks up a branch by short name and returns a fully qualified ref. |
| 310 | func resolveBranchRef(client *api.Client, host, owner, repo, branch string) (*ResolvedRef, error) { |
| 311 | refPath, err := safeurl.JoinPath("repos", owner, repo, "git", "ref", fmt.Sprintf("heads/%s", branch)) |
| 312 | if err != nil { |
| 313 | return nil, err |
| 314 | } |
| 315 | var refResp struct { |
| 316 | Object struct { |
| 317 | SHA string `json:"sha"` |
| 318 | } `json:"object"` |
| 319 | } |
| 320 | if err := client.REST(host, "GET", refPath.String(), nil, &refResp); err != nil { |
| 321 | return nil, fmt.Errorf("branch %q not found in %s/%s: %w", branch, owner, repo, err) |
| 322 | } |
| 323 | return &ResolvedRef{Ref: "refs/heads/" + branch, SHA: refResp.Object.SHA}, nil |
| 324 | } |
| 325 | |
| 326 | // isNotFound returns true if the error is an HTTP 404 response. |
| 327 | func isNotFound(err error) bool { |
no test coverage detected