| 44 | } |
| 45 | |
| 46 | func deleteRepo(httpClient *http.Client, repo ghrepo.Interface) error { |
| 47 | p, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName()) |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | |
| 52 | // If the repo is renamed (and we're using the old name), the API will return |
| 53 | // an HTTP 307 (temporary redirect), which is a METHOD-preserving redirection. |
| 54 | // That is, upon receiving a 307, the HTTP client will repeat the same HTTP |
| 55 | // method (in this case, DELETE) but against the new location. We don't want |
| 56 | // such an implicit behaviour, so we pass the `api.WithoutFollowingRedirects` |
| 57 | // to make sure an error is returned. |
| 58 | resp, err := api.NewClientFromHTTP(httpClient).Request(repo.RepoHost(), http.MethodDelete, p.String(), nil, |
| 59 | api.WithEndpointScopes("delete_repo"), |
| 60 | api.WithoutFollowingRedirects(), |
| 61 | ) |
| 62 | if err != nil { |
| 63 | return err |
| 64 | } |
| 65 | defer resp.Body.Close() |
| 66 | |
| 67 | return nil |
| 68 | } |