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)
| 174 | // fetchRawFile retrieves the raw bytes of a file, used for files larger than the |
| 175 | // 1 MB inline content limit of the Contents API. |
| 176 | func fetchRawFile(httpClient *http.Client, repo ghrepo.Interface, filePath, ref string) ([]byte, error) { |
| 177 | apiPath, err := contentsAPIPath(repo, filePath, ref) |
| 178 | if err != nil { |
| 179 | return nil, err |
| 180 | } |
| 181 | |
| 182 | req, err := http.NewRequest("GET", apiPath.String(), nil) |
| 183 | if err != nil { |
| 184 | return nil, err |
| 185 | } |
| 186 | req.Header.Set("Accept", "application/vnd.github.raw") |
| 187 | |
| 188 | resp, err := httpClient.Do(req) |
| 189 | if err != nil { |
| 190 | return nil, err |
| 191 | } |
| 192 | defer resp.Body.Close() |
| 193 | |
| 194 | if resp.StatusCode > 299 { |
| 195 | return nil, api.HandleHTTPError(resp) |
| 196 | } |
| 197 | |
| 198 | return io.ReadAll(resp.Body) |
| 199 | } |
| 200 | |
| 201 | // contentsAPIPath builds the absolute Contents API URL for a path and optional ref. |
| 202 | func contentsAPIPath(repo ghrepo.Interface, filePath, ref string) (safeurl.SafeURL, error) { |
no test coverage detected