(ctx context.Context, githubClient *github.Client, owner, repo string)
| 303 | } |
| 304 | |
| 305 | func 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 | } |
no test coverage detected