MCPcopy
hub / github.com/cli/cli / createGist

Function createGist

pkg/cmd/gist/create/create.go:262–300  ·  view source on GitHub ↗
(client *http.Client, hostname, description string, public bool, files map[string]*shared.GistFile)

Source from the content-addressed store, hash-verified

260}
261
262func createGist(client *http.Client, hostname, description string, public bool, files map[string]*shared.GistFile) (*shared.Gist, error) {
263 body := &shared.Gist{
264 Description: description,
265 Public: public,
266 Files: files,
267 }
268
269 requestBody := &bytes.Buffer{}
270 enc := json.NewEncoder(requestBody)
271 if err := enc.Encode(body); err != nil {
272 return nil, err
273 }
274
275 u := ghinstance.RESTPrefix(hostname) + "gists"
276 req, err := http.NewRequest(http.MethodPost, u, requestBody)
277 if err != nil {
278 return nil, err
279 }
280 req.Header.Set("Content-Type", "application/json; charset=utf-8")
281
282 resp, err := client.Do(req)
283 if err != nil {
284 return nil, err
285 }
286 defer resp.Body.Close()
287
288 if resp.StatusCode > 299 {
289 api.EndpointNeedsScopes(resp, "gist")
290 return nil, api.HandleHTTPError(resp)
291 }
292
293 result := &shared.Gist{}
294 dec := json.NewDecoder(resp.Body)
295 if err := dec.Decode(result); err != nil {
296 return nil, err
297 }
298
299 return result, nil
300}
301
302func detectEmptyFiles(files map[string]*shared.GistFile) bool {
303 for _, file := range files {

Callers 1

createRunFunction · 0.85

Calls 6

RESTPrefixFunction · 0.92
EndpointNeedsScopesFunction · 0.92
HandleHTTPErrorFunction · 0.92
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected