getLatestBranchCommitSHACached wraps getLatestBranchCommitSHA with a cache keyed by repo+branch to reduce repeated branch-head API lookups.
(ctx context.Context, repo, branch string)
| 341 | // getLatestBranchCommitSHACached wraps getLatestBranchCommitSHA with a cache |
| 342 | // keyed by repo+branch to reduce repeated branch-head API lookups. |
| 343 | func getLatestBranchCommitSHACached(ctx context.Context, repo, branch string) (string, error) { |
| 344 | key := repoBranchKey{repo: repo, branch: branch} |
| 345 | if cached, ok := branchCommitCache.Load(key); ok { |
| 346 | if sha, isString := cached.(string); isString { |
| 347 | return sha, nil |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | sha, err := getLatestBranchCommitSHA(ctx, repo, branch) |
| 352 | if err != nil { |
| 353 | return "", err |
| 354 | } |
| 355 | branchCommitCache.Store(key, sha) |
| 356 | return sha, nil |
| 357 | } |
| 358 | |
| 359 | // fetchPublicGitHubAPI makes an unauthenticated GET request to the GitHub public |
| 360 | // REST API. This is used as a fallback when the current token (e.g. an enterprise |
no test coverage detected