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

Function GetRawGistFile

pkg/cmd/gist/shared/shared.go:255–279  ·  view source on GitHub ↗

GetRawGistFile fetches the full content of a gist file from its raw URL. The bytes are external content, so they are returned as iostreams.Untrusted to force callers to choose between sanitized display and raw round-tripping.

(httpClient *http.Client, rawURL safeurl.SafeURL)

Source from the content-addressed store, hash-verified

253// bytes are external content, so they are returned as iostreams.Untrusted to
254// force callers to choose between sanitized display and raw round-tripping.
255func GetRawGistFile(httpClient *http.Client, rawURL safeurl.SafeURL) (iostreams.Untrusted, error) {
256 req, err := http.NewRequest("GET", rawURL.String(), nil)
257 if err != nil {
258 return iostreams.Untrusted{}, err
259 }
260
261 resp, err := httpClient.Do(req)
262 if err != nil {
263 return iostreams.Untrusted{}, err
264 }
265
266 defer resp.Body.Close()
267
268 if resp.StatusCode != http.StatusOK {
269 return iostreams.Untrusted{}, api.HandleHTTPError(resp)
270 }
271
272 body, err := io.ReadAll(resp.Body)
273
274 if err != nil {
275 return iostreams.Untrusted{}, err
276 }
277
278 return iostreams.NewUntrustedBytes(body), nil
279}

Callers 3

viewRunFunction · 0.92
editRunFunction · 0.92
TestGetRawGistFileFunction · 0.85

Calls 5

HandleHTTPErrorFunction · 0.92
NewUntrustedBytesFunction · 0.92
StringMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestGetRawGistFileFunction · 0.68