summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/branch.go
diff options
context:
space:
mode:
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)
}