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)
| 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. |
| 169 | func 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. |
no test coverage detected