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

Function GetRawGistFile

pkg/cmd/gist/shared/shared.go:257–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. The rawURL is supplied by the API and points at gist.githubusercontent.com

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

Source from the content-addressed store, hash-verified

255// The rawURL is supplied by the API and points at gist.githubusercontent.com rather than the
256// API host, so it is requested as an absolute URL. The hostname only configures the client.
257func GetRawGistFile(httpClient *http.Client, hostname string, rawURL safeurl.SafeURL) (iostreams.Untrusted, error) {
258 // TODO(api-client-rollout)
259 // This line of code is part of a mechanical roll out of the api client.
260 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
261 resp, err := api.NewClientFromHTTP(httpClient).Request(hostname, http.MethodGet, rawURL.String(), nil)
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.UnexpectedStatusError(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 6

NewClientFromHTTPFunction · 0.92
UnexpectedStatusErrorFunction · 0.92
NewUntrustedBytesFunction · 0.92
RequestMethod · 0.80
StringMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestGetRawGistFileFunction · 0.68