The returned response from `api.EndpointNeedsScopes` causes `bodyclose` linter to raise a false positive error, assuming it's a new response that its body needs to be closed. Signed-off-by: Babak K. Shandiz <babakks@github.com>
40 lines
797 B
Go
40 lines
797 B
Go
package delete
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/cli/cli/v2/api"
|
|
"github.com/cli/cli/v2/internal/ghinstance"
|
|
"github.com/cli/cli/v2/internal/ghrepo"
|
|
)
|
|
|
|
func deleteRepo(client *http.Client, repo ghrepo.Interface) error {
|
|
oldClient := *client
|
|
client = &oldClient
|
|
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
|
return http.ErrUseLastResponse
|
|
}
|
|
|
|
url := fmt.Sprintf("%srepos/%s",
|
|
ghinstance.RESTPrefix(repo.RepoHost()),
|
|
ghrepo.FullName(repo))
|
|
|
|
request, err := http.NewRequest("DELETE", url, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
resp, err := client.Do(request)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode > 299 {
|
|
api.EndpointNeedsScopes(resp, "delete_repo")
|
|
return api.HandleHTTPError(resp)
|
|
}
|
|
|
|
return nil
|
|
}
|