summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/git_hook.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2019-12-20 18:07:12 +0100
committerLauris BH <lauris@nix.lv>2019-12-20 19:07:12 +0200
commit2848c5eb8f7333b6791afd296b12d21751d0516b (patch)
tree67ff6244026174116edbff1b4c4cdb5934401968 /routers/api/v1/repo/git_hook.go
parent050a8af4243d7f5fff0a2f492b9166f4dfdf0ecf (diff)
downloadgitea-2848c5eb8f7333b6791afd296b12d21751d0516b.tar.gz
gitea-2848c5eb8f7333b6791afd296b12d21751d0516b.zip
Swagger info corrections (#9441)
* use numbers and not http.Status___ enum * fix test * add many missing swagger responses * code format * Deletion Sould return 204 ... * error handling improvements * if special error type ... then add it to swagger too * one smal nit * invalidTopicsError is []string * valid swagger specification 2.0 - if you add responses swagger can tell you if you do it right :+1: * use ctx.InternalServerError * Revert "use numbers and not http.Status___ enum" This reverts commit b1ff386e2418ed6a7f183e756b13277d701278ef. * use http.Status* enum everywhere
Diffstat (limited to 'routers/api/v1/repo/git_hook.go')
-rw-r--r--routers/api/v1/repo/git_hook.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/routers/api/v1/repo/git_hook.go b/routers/api/v1/repo/git_hook.go
index 46651ef614..0c538ac6b3 100644
--- a/routers/api/v1/repo/git_hook.go
+++ b/routers/api/v1/repo/git_hook.go
@@ -5,6 +5,8 @@
package repo
import (
+ "net/http"
+
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
@@ -32,9 +34,10 @@ func ListGitHooks(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/GitHookList"
+
hooks, err := ctx.Repo.GitRepo.Hooks()
if err != nil {
- ctx.Error(500, "Hooks", err)
+ ctx.Error(http.StatusInternalServerError, "Hooks", err)
return
}
@@ -42,7 +45,7 @@ func ListGitHooks(ctx *context.APIContext) {
for i := range hooks {
apiHooks[i] = convert.ToGitHook(hooks[i])
}
- ctx.JSON(200, &apiHooks)
+ ctx.JSON(http.StatusOK, &apiHooks)
}
// GetGitHook get a repo's Git hook by id
@@ -73,17 +76,18 @@ func GetGitHook(ctx *context.APIContext) {
// "$ref": "#/responses/GitHook"
// "404":
// "$ref": "#/responses/notFound"
+
hookID := ctx.Params(":id")
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
if err != nil {
if err == git.ErrNotValidHook {
ctx.NotFound()
} else {
- ctx.Error(500, "GetHook", err)
+ ctx.Error(http.StatusInternalServerError, "GetHook", err)
}
return
}
- ctx.JSON(200, convert.ToGitHook(hook))
+ ctx.JSON(http.StatusOK, convert.ToGitHook(hook))
}
// EditGitHook modify a Git hook of a repository
@@ -118,24 +122,25 @@ func EditGitHook(ctx *context.APIContext, form api.EditGitHookOption) {
// "$ref": "#/responses/GitHook"
// "404":
// "$ref": "#/responses/notFound"
+
hookID := ctx.Params(":id")
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
if err != nil {
if err == git.ErrNotValidHook {
ctx.NotFound()
} else {
- ctx.Error(500, "GetHook", err)
+ ctx.Error(http.StatusInternalServerError, "GetHook", err)
}
return
}
hook.Content = form.Content
if err = hook.Update(); err != nil {
- ctx.Error(500, "hook.Update", err)
+ ctx.Error(http.StatusInternalServerError, "hook.Update", err)
return
}
- ctx.JSON(200, convert.ToGitHook(hook))
+ ctx.JSON(http.StatusOK, convert.ToGitHook(hook))
}
// DeleteGitHook delete a Git hook of a repository
@@ -166,22 +171,23 @@ func DeleteGitHook(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
+
hookID := ctx.Params(":id")
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
if err != nil {
if err == git.ErrNotValidHook {
ctx.NotFound()
} else {
- ctx.Error(500, "GetHook", err)
+ ctx.Error(http.StatusInternalServerError, "GetHook", err)
}
return
}
hook.Content = ""
if err = hook.Update(); err != nil {
- ctx.Error(500, "hook.Update", err)
+ ctx.Error(http.StatusInternalServerError, "hook.Update", err)
return
}
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
}