diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-03-19 23:39:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-19 11:39:08 -0400 |
commit | 83fe7d414e2bcef21e61f0bbfc719125973a61c2 (patch) | |
tree | 658017c9ba80c09f1aa069eef63cd658752cb44c /modules/convert/convert.go | |
parent | 661289d48039d403a68033c5788b83d9b53cb3aa (diff) | |
download | gitea-83fe7d414e2bcef21e61f0bbfc719125973a61c2.tar.gz gitea-83fe7d414e2bcef21e61f0bbfc719125973a61c2.zip |
Fix bug on branch API (#10767)
Diffstat (limited to 'modules/convert/convert.go')
-rw-r--r-- | modules/convert/convert.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go index cab2f84bb9..240db77d2c 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -49,17 +49,21 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models. branchProtectionName = bp.BranchName } - return &api.Branch{ + branch := &api.Branch{ 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.IsUserMergeWhitelisted(user.ID), EffectiveBranchProtectionName: branchProtectionName, } + + if user != nil { + branch.UserCanPush = bp.CanUserPush(user.ID) + branch.UserCanMerge = bp.IsUserMergeWhitelisted(user.ID) + } + return branch } // ToBranchProtection convert a ProtectedBranch to api.BranchProtection |