resolveBranchRef looks up a branch by short name and returns a fully qualified ref.
(client *api.Client, host, owner, repo, branch string)
| 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) { |
| 298 | refPath := fmt.Sprintf("repos/%s/%s/git/ref/heads/%s", url.PathEscape(owner), url.PathEscape(repo), url.PathEscape(branch)) |
| 299 | var refResp struct { |
| 300 | Object struct { |
| 301 | SHA string `json:"sha"` |
| 302 | } `json:"object"` |
| 303 | } |
| 304 | if err := client.REST(host, "GET", refPath, nil, &refResp); err != nil { |
| 305 | return nil, fmt.Errorf("branch %q not found in %s/%s: %w", branch, owner, repo, err) |
| 306 | } |
| 307 | return &ResolvedRef{Ref: "refs/heads/" + branch, SHA: refResp.Object.SHA}, nil |
| 308 | } |
| 309 | |
| 310 | // isNotFound returns true if the error is an HTTP 404 response. |
| 311 | func isNotFound(err error) bool { |
no test coverage detected