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

Function createGist

pkg/cmd/gist/create/create.go:262–297  ·  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 path, err := safeurl.JoinPath("gists")
276 if err != nil {
277 return nil, err
278 }
279
280 // TODO(api-client-rollout)
281 // This line of code is part of a mechanical roll out of the api client.
282 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
283 resp, err := api.NewClientFromHTTP(client).Request(hostname, http.MethodPost, path.String(), requestBody,
284 api.WithEndpointScopes("gist"))
285 if err != nil {
286 return nil, err
287 }
288 defer resp.Body.Close()
289
290 result := &shared.Gist{}
291 dec := json.NewDecoder(resp.Body)
292 if err := dec.Decode(result); err != nil {
293 return nil, err
294 }
295
296 return result, nil
297}
298
299func detectEmptyFiles(files map[string]*shared.GistFile) bool {
300 for _, file := range files {

Callers 2

createRunFunction · 0.85

Calls 6

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
WithEndpointScopesFunction · 0.92
RequestMethod · 0.80
StringMethod · 0.65
CloseMethod · 0.65

Tested by 1