From 28e96a3851f5dbca7281fc6a7ec28d601d1ef46a Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Thu, 24 Feb 2022 14:54:05 +0100 Subject: [PATCH] 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///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. --- server/remote/gitea/gitea.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/server/remote/gitea/gitea.go b/server/remote/gitea/gitea.go index 3259096ab..fb29823b2 100644 --- a/server/remote/gitea/gitea.go +++ b/server/remote/gitea/gitea.go @@ -381,8 +381,19 @@ func (c *Gitea) Activate(ctx context.Context, u *model.User, r *model.Repo, link if err != nil { return err } - _, _, err = client.CreateRepoHook(r.Owner, r.Name, hook) - return err + _, 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 nil } // Deactivate deactives the repository be removing repository push hooks from