summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/branch.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/branch.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/branch.go')
-rw-r--r--routers/api/v1/repo/branch.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index 9745903a95..afc4763b52 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -6,6 +6,8 @@
package repo
import (
+ "net/http"
+
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
@@ -38,6 +40,7 @@ func GetBranch(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Branch"
+
if ctx.Repo.TreePath != "" {
// if TreePath != "", then URL contained extra slashes
// (i.e. "master/subbranch" instead of "master"), so branch does
@@ -50,24 +53,24 @@ func GetBranch(ctx *context.APIContext) {
if git.IsErrBranchNotExist(err) {
ctx.NotFound(err)
} else {
- ctx.Error(500, "GetBranch", err)
+ ctx.Error(http.StatusInternalServerError, "GetBranch", err)
}
return
}
c, err := branch.GetCommit()
if err != nil {
- ctx.Error(500, "GetCommit", err)
+ ctx.Error(http.StatusInternalServerError, "GetCommit", err)
return
}
branchProtection, err := ctx.Repo.Repository.GetBranchProtection(ctx.Repo.BranchName)
if err != nil {
- ctx.Error(500, "GetBranchProtection", err)
+ ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
return
}
- ctx.JSON(200, convert.ToBranch(ctx.Repo.Repository, branch, c, branchProtection, ctx.User))
+ ctx.JSON(http.StatusOK, convert.ToBranch(ctx.Repo.Repository, branch, c, branchProtection, ctx.User))
}
// ListBranches list all the branches of a repository
@@ -91,9 +94,10 @@ func ListBranches(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/BranchList"
+
branches, err := ctx.Repo.Repository.GetBranches()
if err != nil {
- ctx.Error(500, "GetBranches", err)
+ ctx.Error(http.StatusInternalServerError, "GetBranches", err)
return
}
@@ -101,16 +105,16 @@ func ListBranches(ctx *context.APIContext) {
for i := range branches {
c, err := branches[i].GetCommit()
if err != nil {
- ctx.Error(500, "GetCommit", err)
+ ctx.Error(http.StatusInternalServerError, "GetCommit", err)
return
}
branchProtection, err := ctx.Repo.Repository.GetBranchProtection(branches[i].Name)
if err != nil {
- ctx.Error(500, "GetBranchProtection", err)
+ ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
return
}
apiBranches[i] = convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.User)
}
- ctx.JSON(200, &apiBranches)
+ ctx.JSON(http.StatusOK, &apiBranches)
}