| 9 | ) |
| 10 | |
| 11 | func deleteRepo(httpClient *http.Client, repo ghrepo.Interface) error { |
| 12 | p, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName()) |
| 13 | if err != nil { |
| 14 | return err |
| 15 | } |
| 16 | |
| 17 | // If the repo is renamed (and we're using the old name), the API will return |
| 18 | // an HTTP 307 (temporary redirect), which is a METHOD-preserving redirection. |
| 19 | // That is, upon receiving a 307, the HTTP client will repeat the same HTTP |
| 20 | // method (in this case, DELETE) but against the new location. We don't want |
| 21 | // such an implicit behaviour, so we pass the `api.WithoutFollowingRedirects` |
| 22 | // to make sure an error is returned. |
| 23 | resp, err := api.NewClientFromHTTP(httpClient).Request(repo.RepoHost(), http.MethodDelete, p.String(), nil, |
| 24 | api.WithEndpointScopes("delete_repo"), |
| 25 | api.WithoutFollowingRedirects(), |
| 26 | ) |
| 27 | if err != nil { |
| 28 | return err |
| 29 | } |
| 30 | defer resp.Body.Close() |
| 31 | |
| 32 | return nil |
| 33 | } |