View better error if repo was deleted/renamed (#780)

If the repo was renamed, there's an issue with Gitea: it redirects the /api/v1/repos/<owner>/<repo>/hooks POST request to a GET request at the same URL.
This URL returns the list of all hooks, thus the Gitea SDK can't parse the response into a single gitea.Hook type.

A better error is also visisble if the repo was deleted.
This commit is contained in:
qwerty287 2022-02-24 14:54:05 +01:00 committed by GitHub
parent c4960cdd2c
commit 28e96a3851
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -381,9 +381,20 @@ func (c *Gitea) Activate(ctx context.Context, u *model.User, r *model.Repo, link
if err != nil { if err != nil {
return err return err
} }
_, _, err = client.CreateRepoHook(r.Owner, r.Name, hook) _, response, err := client.CreateRepoHook(r.Owner, r.Name, hook)
if err != nil {
if response != nil {
if response.StatusCode == 404 {
return fmt.Errorf("Could not find repository")
}
if response.StatusCode == 200 {
return fmt.Errorf("Could not find repository, repository was probably renamed")
}
}
return err return err
} }
return nil
}
// Deactivate deactives the repository be removing repository push hooks from // Deactivate deactives the repository be removing repository push hooks from
// the Gitea repository. // the Gitea repository.