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

Function GetRawGistFile

pkg/cmd/gist/shared/shared.go:258–282  ·  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

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

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