Skip to content

Commit 83fe7d4

Browse files
authored
Fix bug on branch API (#10767)
1 parent 661289d commit 83fe7d4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

modules/convert/convert.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,21 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
4949
branchProtectionName = bp.BranchName
5050
}
5151

52-
return &api.Branch{
52+
branch := &api.Branch{
5353
Name: b.Name,
5454
Commit: ToCommit(repo, c),
5555
Protected: true,
5656
RequiredApprovals: bp.RequiredApprovals,
5757
EnableStatusCheck: bp.EnableStatusCheck,
5858
StatusCheckContexts: bp.StatusCheckContexts,
59-
UserCanPush: bp.CanUserPush(user.ID),
60-
UserCanMerge: bp.IsUserMergeWhitelisted(user.ID),
6159
EffectiveBranchProtectionName: branchProtectionName,
6260
}
61+
62+
if user != nil {
63+
branch.UserCanPush = bp.CanUserPush(user.ID)
64+
branch.UserCanMerge = bp.IsUserMergeWhitelisted(user.ID)
65+
}
66+
return branch
6367
}
6468

6569
// ToBranchProtection convert a ProtectedBranch to api.BranchProtection

0 commit comments

Comments
 (0)