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

Function downloadFileViaRawURL

pkg/parser/remote_fetch.go:652–682  ·  view source on GitHub ↗

downloadFileViaRawURL fetches a file using the raw.githubusercontent.com URL. This requires no authentication for public repositories and no git installation.

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

Source from the content-addressed store, hash-verified

650// downloadFileViaRawURL fetches a file using the raw.githubusercontent.com URL.
651// This requires no authentication for public repositories and no git installation.
652func downloadFileViaRawURL(ctx context.Context, owner, repo, filePath, ref string) ([]byte, error) {
653 rawURL := fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/%s", owner, repo, ref, filePath)
654 remoteLog.Printf("Attempting raw URL download: %s", rawURL)
655
656 // Use a client with a timeout to prevent indefinite hangs on slow/unresponsive hosts.
657 rawClient := &http.Client{Timeout: constants.DefaultHTTPClientTimeout}
658
659 // #nosec G107 -- rawURL is constructed from workflow import configuration authored by
660 // the developer; the owner, repo, filePath, and ref are user-supplied workflow spec fields.
661 req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil)
662 if err != nil {
663 return nil, fmt.Errorf("raw URL request failed for %s: %w", rawURL, err)
664 }
665 resp, err := rawClient.Do(req)
666 if err != nil {
667 return nil, fmt.Errorf("raw URL request failed for %s: %w", rawURL, err)
668 }
669 defer resp.Body.Close()
670
671 if resp.StatusCode != http.StatusOK {
672 return nil, fmt.Errorf("raw URL returned HTTP %d for %s", resp.StatusCode, rawURL)
673 }
674
675 content, err := io.ReadAll(resp.Body)
676 if err != nil {
677 return nil, fmt.Errorf("failed to read raw URL response body for %s: %w", rawURL, err)
678 }
679
680 remoteLog.Printf("Successfully downloaded file via raw URL: %s", rawURL)
681 return content, nil
682}
683
684// downloadFileViaGitClone downloads a file by shallow cloning the repository
685// This is used as a fallback when git archive doesn't work

Callers 1

downloadFileViaGitFunction · 0.85

Calls 3

CloseMethod · 0.65
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected