MCPcopy Index your code
hub / github.com/google/go-github / GetBranch

Method GetBranch

github/repos.go:1465–1481  ·  view source on GitHub ↗

GetBranch gets the specified branch for a repository. Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape . GitHub API docs: https://docs.github.com/rest/branches/branches?apiVersion=2022-11-28#get-a-branch meta:operation GET /repos/{owner}/{repo}/branche

(ctx context.Context, owner, repo, branch string, maxRedirects int)

Source from the content-addressed store, hash-verified

1463//
1464//meta:operation GET /repos/{owner}/{repo}/branches/{branch}
1465func (s *RepositoriesService) GetBranch(ctx context.Context, owner, repo, branch string, maxRedirects int) (*Branch, *Response, error) {
1466 u := fmt.Sprintf("repos/%v/%v/branches/%v", owner, repo, url.PathEscape(branch))
1467
1468 resp, err := s.client.roundTripWithOptionalFollowRedirect(ctx, u, maxRedirects)
1469 if err != nil {
1470 return nil, nil, err
1471 }
1472 defer resp.Body.Close()
1473
1474 if resp.StatusCode != http.StatusOK {
1475 return nil, newResponse(resp), fmt.Errorf("unexpected status code: %v", resp.Status)
1476 }
1477
1478 var b *Branch
1479 err = json.NewDecoder(resp.Body).Decode(&b)
1480 return b, newResponse(resp), err
1481}
1482
1483// renameBranchRequest represents a request to rename a branch.
1484type renameBranchRequest struct {

Calls 3

newResponseFunction · 0.85
CloseMethod · 0.80