MCPcopy Create free account
hub / github.com/github/gh-aw / resolveDefaultBranchRef

Function resolveDefaultBranchRef

pkg/cli/update_redirects.go:118–126  ·  view source on GitHub ↗

resolveDefaultBranchRef returns the repository's default branch name via the GitHub API. When the source field omits a branch ref we must track the repo's actual default branch (which may be "master", "trunk", etc.) rather than assuming "main". If the API lookup fails, it falls back to "main" so res

(ctx context.Context, repo string)

Source from the content-addressed store, hash-verified

116// assuming "main". If the API lookup fails, it falls back to "main" so resolution
117// can still proceed in offline or rate-limited scenarios.
118func resolveDefaultBranchRef(ctx context.Context, repo string) string {
119 branch, err := getRepoDefaultBranchCached(ctx, repo)
120 if err != nil || strings.TrimSpace(branch) == "" {
121 updateRedirectsLog.Printf("Falling back to 'main' as default branch for %s: %v", repo, err)
122 return "main"
123 }
124 updateRedirectsLog.Printf("Resolved default branch for %s: %s", repo, branch)
125 return branch
126}
127
128func extractRedirectFromContent(content string) (string, error) {
129 result, err := parser.ExtractFrontmatterFromContent(content)

Callers 1

Calls 2

PrintfMethod · 0.45

Tested by

no test coverage detected