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

Function fetchPublicGitHubAPI

pkg/cli/update_workflows.go:364–386  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
364func 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.
389func getRepoDefaultBranch(ctx context.Context, repo string) (string, error) {

Callers 3

getRepoDefaultBranchFunction · 0.85
getLatestBranchCommitSHAFunction · 0.85

Calls 3

CloseMethod · 0.65
SetMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected