summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorDavid Svantesson <davidsvantesson@gmail.com>2019-11-16 20:39:18 +0100
committerzeripath <art27@cantab.net>2019-11-16 19:39:18 +0000
commit86cff86b46116353e4d6605ccf5a77a7ac65bc78 (patch)
treec4b0cefc24d333f64682d9b31a91ad42406a6aef /routers
parent3dfe9190b05b68497478324a776c1f80d6f5e56d (diff)
downloadgitea-86cff86b46116353e4d6605ccf5a77a7ac65bc78.tar.gz
gitea-86cff86b46116353e4d6605ccf5a77a7ac65bc78.zip
Update branch API endpoint to show effective branch protection. (#9031)
* Add API endpoint for displaying effective branch protection. * Add status checks.
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/branch.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index 9f6a2e6294..9745903a95 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -16,7 +16,7 @@ import (
func GetBranch(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/branches/{branch} repository repoGetBranch
// ---
- // summary: Retrieve a specific branch from a repository
+ // summary: Retrieve a specific branch from a repository, including its effective branch protection
// produces:
// - application/json
// parameters:
@@ -61,7 +61,13 @@ func GetBranch(ctx *context.APIContext) {
return
}
- ctx.JSON(200, convert.ToBranch(ctx.Repo.Repository, branch, c))
+ branchProtection, err := ctx.Repo.Repository.GetBranchProtection(ctx.Repo.BranchName)
+ if err != nil {
+ ctx.Error(500, "GetBranchProtection", err)
+ return
+ }
+
+ ctx.JSON(200, convert.ToBranch(ctx.Repo.Repository, branch, c, branchProtection, ctx.User))
}
// ListBranches list all the branches of a repository
@@ -98,7 +104,12 @@ func ListBranches(ctx *context.APIContext) {
ctx.Error(500, "GetCommit", err)
return
}
- apiBranches[i] = convert.ToBranch(ctx.Repo.Repository, branches[i], c)
+ branchProtection, err := ctx.Repo.Repository.GetBranchProtection(branches[i].Name)
+ if err != nil {
+ ctx.Error(500, "GetBranchProtection", err)
+ return
+ }
+ apiBranches[i] = convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.User)
}
ctx.JSON(200, &apiBranches)