MCPcopy
hub / github.com/github/github-mcp-server / resolveDefaultBranch

Function resolveDefaultBranch

pkg/github/repositories_helper.go:305–329  ·  view source on GitHub ↗
(ctx context.Context, githubClient *github.Client, owner, repo string)

Source from the content-addressed store, hash-verified

303}
304
305func resolveDefaultBranch(ctx context.Context, githubClient *github.Client, owner, repo string) (*github.Reference, error) {
306 repoInfo, resp, err := githubClient.Repositories.Get(ctx, owner, repo)
307 if err != nil {
308 _, _ = ghErrors.NewGitHubAPIErrorToCtx(ctx, "failed to get repository info", resp, err)
309 return nil, fmt.Errorf("failed to get repository info: %w", err)
310 }
311
312 if resp != nil && resp.Body != nil {
313 _ = resp.Body.Close()
314 }
315
316 defaultBranch := repoInfo.GetDefaultBranch()
317
318 defaultRef, resp, err := githubClient.Git.GetRef(ctx, owner, repo, "heads/"+defaultBranch)
319 if err != nil {
320 _, _ = ghErrors.NewGitHubAPIErrorToCtx(ctx, "failed to get default branch reference", resp, err)
321 return nil, fmt.Errorf("failed to get default branch reference: %w", err)
322 }
323
324 if resp != nil && resp.Body != nil {
325 defer func() { _ = resp.Body.Close() }()
326 }
327
328 return defaultRef, nil
329}

Callers 2

resolveGitReferenceFunction · 0.85

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected