MCPcopy Index your code
hub / github.com/cli/cli / resolveBranchRef

Function resolveBranchRef

internal/skills/discovery/discovery.go:297–308  ·  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

295
296// resolveBranchRef looks up a branch by short name and returns a fully qualified ref.
297func 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.
311func isNotFound(err error) bool {

Callers 2

resolveExplicitRefFunction · 0.85
resolveDefaultBranchFunction · 0.85

Calls 2

RESTMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected