MCPcopy Create free account
hub / github.com/cli/cli / fetchRawFile

Function fetchRawFile

pkg/cmd/repo/read-file/http.go:169–186  ·  view source on GitHub ↗

fetchRawFile retrieves the raw bytes of a file, used for files larger than the 1 MB inline content limit of the Contents API.

(httpClient *http.Client, repo ghrepo.Interface, filePath, ref string)

Source from the content-addressed store, hash-verified

167// fetchRawFile retrieves the raw bytes of a file, used for files larger than the
168// 1 MB inline content limit of the Contents API.
169func fetchRawFile(httpClient *http.Client, repo ghrepo.Interface, filePath, ref string) ([]byte, error) {
170 apiPath, err := contentsAPIPath(repo, filePath, ref)
171 if err != nil {
172 return nil, err
173 }
174
175 // TODO(api-client-rollout)
176 // This line of code is part of a mechanical roll out of the api client.
177 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
178 resp, err := api.NewClientFromHTTP(httpClient).Request(repo.RepoHost(), http.MethodGet, apiPath.String(), nil,
179 api.WithHeader("Accept", "application/vnd.github.raw"))
180 if err != nil {
181 return nil, err
182 }
183 defer resp.Body.Close()
184
185 return io.ReadAll(resp.Body)
186}
187
188// contentsAPIPath builds the Contents API path for a path and optional ref, relative to the
189// host's REST endpoint.

Callers 1

loadContentFunction · 0.85

Calls 7

NewClientFromHTTPFunction · 0.92
WithHeaderFunction · 0.92
contentsAPIPathFunction · 0.85
RequestMethod · 0.80
RepoHostMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected