Skip to content

Commit d8522ac

Browse files
committed
re-use code
1 parent 26d686f commit d8522ac

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed

services/pull/update.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,26 +234,11 @@ func Update(pull *models.PullRequest, doer *models.User, message string) (err er
234234

235235
// IsUserAllowedToUpdate check if user is allowed to update PR with given permissions and branch protections
236236
func IsUserAllowedToUpdate(pull *models.PullRequest, p models.Permission, user *models.User) (bool, error) {
237-
if p.IsAdmin() {
238-
return true, nil
239-
}
240-
if !p.CanWrite(models.UnitTypeCode) {
241-
return false, nil
242-
}
243237
pr := &models.PullRequest{
244238
HeadRepoID: pull.BaseRepoID,
245239
BaseRepoID: pull.HeadRepoID,
246240
HeadBranch: pull.BaseBranch,
247241
BaseBranch: pull.HeadBranch,
248242
}
249-
err := pr.LoadProtectedBranch()
250-
if err != nil {
251-
return false, err
252-
}
253-
254-
if pr.ProtectedBranch == nil || pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID) {
255-
return true, nil
256-
}
257-
258-
return false, nil
243+
return IsUserAllowedToMerge(pr, p, user)
259244
}

0 commit comments

Comments
 (0)