delete repository need a token with scope 'delete_repo'
(project, owner, token string)
| 342 | |
| 343 | // delete repository need a token with scope 'delete_repo' |
| 344 | func deleteRepository(project, owner, token string) error { |
| 345 | // This function use the V3 Github API because repository removal is not supported yet on the V4 API. |
| 346 | url := fmt.Sprintf("%s/repos/%s/%s", githubV3Url, owner, project) |
| 347 | |
| 348 | req, err := http.NewRequest("DELETE", url, nil) |
| 349 | if err != nil { |
| 350 | return err |
| 351 | } |
| 352 | |
| 353 | // need the token for private repositories |
| 354 | req.Header.Set("Authorization", fmt.Sprintf("token %s", token)) |
| 355 | |
| 356 | client := &http.Client{ |
| 357 | Timeout: defaultTimeout, |
| 358 | } |
| 359 | |
| 360 | resp, err := client.Do(req) |
| 361 | if err != nil { |
| 362 | return err |
| 363 | } |
| 364 | |
| 365 | defer resp.Body.Close() |
| 366 | |
| 367 | if resp.StatusCode != http.StatusNoContent { |
| 368 | return fmt.Errorf("error deleting repository") |
| 369 | } |
| 370 | |
| 371 | return nil |
| 372 | } |
no test coverage detected