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

Function resolveBranchRef

internal/skills/discovery/discovery.go:310–324  ·  view source on GitHub ↗

resolveBranchRef looks up a branch by short name and returns a fully qualified ref.

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

Source from the content-addressed store, hash-verified

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) {
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.
327func isNotFound(err error) bool {

Callers 2

resolveExplicitRefFunction · 0.85
resolveDefaultBranchFunction · 0.85

Calls 4

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

Tested by

no test coverage detected