resolveLatestCommitFromDefaultBranch fetches the latest commit SHA from the default branch of a repo. This is used when the source field is pinned to a commit SHA with no branch information — in that case we can only logically track the default branch.
(ctx context.Context, repo, currentSHA string, verbose bool)
| 299 | // to a commit SHA with no branch information — in that case we can only |
| 300 | // logically track the default branch. |
| 301 | func resolveLatestCommitFromDefaultBranch(ctx context.Context, repo, currentSHA string, verbose bool) (string, error) { |
| 302 | // Get the default branch name |
| 303 | defaultBranch, err := getRepoDefaultBranchCached(ctx, repo) |
| 304 | if err != nil { |
| 305 | return "", fmt.Errorf("failed to get default branch for %s: %w", repo, err) |
| 306 | } |
| 307 | |
| 308 | updateLog.Printf("Source is pinned to commit SHA, tracking default branch %q of %s", defaultBranch, repo) |
| 309 | if verbose { |
| 310 | fmt.Fprintln(os.Stderr, console.FormatVerboseMessage(fmt.Sprintf("Source has no branch ref, tracking default branch %q", defaultBranch))) |
| 311 | } |
| 312 | |
| 313 | // Get the latest commit SHA from the default branch |
| 314 | latestSHA, err := getLatestBranchCommitSHACached(ctx, repo, defaultBranch) |
| 315 | if err != nil { |
| 316 | return "", fmt.Errorf("failed to get latest commit for default branch %s: %w", defaultBranch, err) |
| 317 | } |
| 318 | |
| 319 | updateLog.Printf("Latest commit on default branch %s: %s (current: %s)", defaultBranch, latestSHA, currentSHA) |
| 320 | |
| 321 | return latestSHA, nil |
| 322 | } |
| 323 | |
| 324 | // getRepoDefaultBranchCached wraps getRepoDefaultBranch with a cache to avoid |
| 325 | // repeating identical GitHub API calls during batched update runs. |
no test coverage detected