(client *http.Client, hostname, description string, public bool, files map[string]*shared.GistFile)
| 260 | } |
| 261 | |
| 262 | func 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 | |
| 302 | func detectEmptyFiles(files map[string]*shared.GistFile) bool { |
| 303 | for _, file := range files { |
no test coverage detected