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

Function downloadFileViaPublicAPI

pkg/parser/remote_fetch.go:987–1010  ·  view source on GitHub ↗

downloadFileViaPublicAPI downloads a file from a public GitHub repository using an unauthenticated API call. Used as a last-resort fallback when both authenticated API and git clone fail (e.g. enterprise SAML tokens).

(ctx context.Context, owner, repo, path, ref string)

Source from the content-addressed store, hash-verified

985// using an unauthenticated API call. Used as a last-resort fallback when both
986// authenticated API and git clone fail (e.g. enterprise SAML tokens).
987func downloadFileViaPublicAPI(ctx context.Context, owner, repo, path, ref string) ([]byte, error) {
988 remoteLog.Printf("Attempting unauthenticated public API download for %s/%s/%s@%s", owner, repo, path, ref)
989 body, err := fetchPublicGitHubContentsAPI(ctx, owner, repo, path, ref)
990 if err != nil {
991 return nil, fmt.Errorf("unauthenticated public API also failed for %s/%s/%s@%s: %w", owner, repo, path, ref, err)
992 }
993
994 var fileContent struct {
995 Content string `json:"content"`
996 Encoding string `json:"encoding"`
997 }
998 if err := json.Unmarshal(body, &fileContent); err != nil {
999 return nil, fmt.Errorf("failed to parse public API file response: %w", err)
1000 }
1001 if fileContent.Content == "" {
1002 return nil, fmt.Errorf("empty content returned from public API for %s/%s/%s@%s", owner, repo, path, ref)
1003 }
1004
1005 content, err := base64.StdEncoding.DecodeString(fileContent.Content)
1006 if err != nil {
1007 return nil, fmt.Errorf("failed to decode base64 content from public API: %w", err)
1008 }
1009 return content, nil
1010}
1011
1012func retryDownloadViaResolvedSymlink(
1013 client *api.RESTClient,

Callers 1

Calls 3

PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected