fetchPublicGitHubAPI makes an unauthenticated GET request to the GitHub public REST API. This is used as a fallback when the current token (e.g. an enterprise SAML-enforced token) cannot access cross-organization public repositories. Unauthenticated requests are subject to a lower rate limit (60 req
(ctx context.Context, endpoint string)
| 362 | // Unauthenticated requests are subject to a lower rate limit (60 req/hour) but |
| 363 | // are sufficient for the handful of calls needed during update resolution. |
| 364 | func fetchPublicGitHubAPI(ctx context.Context, endpoint string) ([]byte, error) { |
| 365 | apiURL := "https://api.github.com" + endpoint |
| 366 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, apiURL, nil) |
| 367 | if err != nil { |
| 368 | return nil, err |
| 369 | } |
| 370 | req.Header.Set("Accept", "application/vnd.github+json") |
| 371 | |
| 372 | resp, err := updatePublicAPIClient.Do(req) |
| 373 | if err != nil { |
| 374 | return nil, err |
| 375 | } |
| 376 | defer resp.Body.Close() |
| 377 | |
| 378 | body, err := io.ReadAll(resp.Body) |
| 379 | if err != nil { |
| 380 | return nil, err |
| 381 | } |
| 382 | if resp.StatusCode != http.StatusOK { |
| 383 | return nil, fmt.Errorf("GitHub API returned %d: %s", resp.StatusCode, strings.TrimSpace(string(body))) |
| 384 | } |
| 385 | return body, nil |
| 386 | } |
| 387 | |
| 388 | // getRepoDefaultBranch fetches the default branch name for a repository. |
| 389 | func getRepoDefaultBranch(ctx context.Context, repo string) (string, error) { |
no test coverage detected