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