summaryrefslogtreecommitdiffstats
path: root/modules/convert/convert.go
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 /modules/convert/convert.go
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 'modules/convert/convert.go')
-rw-r--r--modules/convert/convert.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go
index f52ed63476..f65e4b4fe2 100644
--- a/modules/convert/convert.go
+++ b/modules/convert/convert.go
@@ -30,10 +30,28 @@ func ToEmail(email *models.EmailAddress) *api.Email {
}
// ToBranch convert a git.Commit and git.Branch to an api.Branch
-func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit) *api.Branch {
+func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *models.User) *api.Branch {
+ if bp == nil {
+ return &api.Branch{
+ Name: b.Name,
+ Commit: ToCommit(repo, c),
+ Protected: false,
+ RequiredApprovals: 0,
+ EnableStatusCheck: false,
+ StatusCheckContexts: []string{},
+ UserCanPush: true,
+ UserCanMerge: true,
+ }
+ }
return &api.Branch{
- Name: b.Name,
- Commit: ToCommit(repo, c),
+ Name: b.Name,
+ Commit: ToCommit(repo, c),
+ Protected: true,
+ RequiredApprovals: bp.RequiredApprovals,
+ EnableStatusCheck: bp.EnableStatusCheck,
+ StatusCheckContexts: bp.StatusCheckContexts,
+ UserCanPush: bp.CanUserPush(user.ID),
+ UserCanMerge: bp.CanUserMerge(user.ID),
}
}