| 259 | } |
| 260 | |
| 261 | func 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 | |
| 298 | func detectEmptyFiles(files map[string]*shared.GistFile) bool { |
| 299 | for _, file := range files { |