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

Function createGist

pkg/cmd/gist/create/create.go:263–304  ·  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

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

Callers 1

createRunFunction · 0.85

Calls 8

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

Tested by

no test coverage detected