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

Function createGist

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

259}
260
261func createGist(client *http.Client, hostname, description string, public bool, files map[string]*shared.GistFile) (*shared.Gist, error) {
262 body := &shared.Gist{
263 Description: description,
264 Public: public,
265 Files: files,
266 }
267
268 requestBody := &bytes.Buffer{}
269 enc := json.NewEncoder(requestBody)
270 if err := enc.Encode(body); err != nil {
271 return nil, err
272 }
273
274 path, err := safeurl.JoinPath("gists")
275 if err != nil {
276 return nil, err
277 }
278
279 // TODO(api-client-rollout)
280 // This line of code is part of a mechanical roll out of the api client.
281 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
282 resp, err := api.NewClientFromHTTP(client).Request(hostname, http.MethodPost, path.String(), requestBody,
283 api.WithEndpointScopes("gist"))
284 if err != nil {
285 return nil, err
286 }
287 defer resp.Body.Close()
288
289 result := &shared.Gist{}
290 dec := json.NewDecoder(resp.Body)
291 if err := dec.Decode(result); err != nil {
292 return nil, err
293 }
294
295 return result, nil
296}
297
298func detectEmptyFiles(files map[string]*shared.GistFile) bool {
299 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