diff options
author | David Svantesson <davidsvantesson@gmail.com> | 2020-01-11 08:29:34 +0100 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2020-01-11 02:29:34 -0500 |
commit | 32fb813133c74ddc3af1964e81fff72fea4f24f1 (patch) | |
tree | 31eec446f12e448d7cf398db43620606e9704ff1 /models | |
parent | 4d06d10dbafe7cfd404889b636d8e243058ee96f (diff) | |
download | gitea-32fb813133c74ddc3af1964e81fff72fea4f24f1.tar.gz gitea-32fb813133c74ddc3af1964e81fff72fea4f24f1.zip |
Allow repo admin to merge PR regardless of review status (#9611)
* Allow repo admin to merge even if review is not ok.
Diffstat (limited to 'models')
-rw-r--r-- | models/branches.go | 25 | ||||
-rw-r--r-- | models/pull.go | 25 | ||||
-rw-r--r-- | models/repo_permission.go | 2 |
3 files changed, 3 insertions, 49 deletions
diff --git a/models/branches.go b/models/branches.go index 1932e06db3..b6398f5694 100644 --- a/models/branches.go +++ b/models/branches.go @@ -93,8 +93,8 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool { return in } -// CanUserMerge returns if some user could merge a pull request to this protected branch -func (protectBranch *ProtectedBranch) CanUserMerge(userID int64) bool { +// IsUserMergeWhitelisted checks if some user is whitelisted to merge to this branch +func (protectBranch *ProtectedBranch) IsUserMergeWhitelisted(userID int64) bool { if !protectBranch.EnableMergeWhitelist { return true } @@ -348,27 +348,6 @@ func (repo *Repository) IsProtectedBranchForPush(branchName string, doer *User) return false, nil } -// IsProtectedBranchForMerging checks if branch is protected for merging -func (repo *Repository) IsProtectedBranchForMerging(pr *PullRequest, branchName string, doer *User) (bool, error) { - if doer == nil { - return true, nil - } - - protectedBranch := &ProtectedBranch{ - RepoID: repo.ID, - BranchName: branchName, - } - - has, err := x.Get(protectedBranch) - if err != nil { - return true, err - } else if has { - return !protectedBranch.CanUserMerge(doer.ID) || !protectedBranch.HasEnoughApprovals(pr) || protectedBranch.MergeBlockedByRejectedReview(pr), nil - } - - return false, nil -} - // updateApprovalWhitelist checks whether the user whitelist changed and returns a whitelist with // the users from newWhitelist which have explicit read or write access to the repo. func updateApprovalWhitelist(repo *Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) { diff --git a/models/pull.go b/models/pull.go index e2a35c5920..bf2527679f 100644 --- a/models/pull.go +++ b/models/pull.go @@ -479,31 +479,6 @@ const ( MergeStyleSquash MergeStyle = "squash" ) -// CheckUserAllowedToMerge checks whether the user is allowed to merge -func (pr *PullRequest) CheckUserAllowedToMerge(doer *User) (err error) { - if doer == nil { - return ErrNotAllowedToMerge{ - "Not signed in", - } - } - - if pr.BaseRepo == nil { - if err = pr.GetBaseRepo(); err != nil { - return fmt.Errorf("GetBaseRepo: %v", err) - } - } - - if protected, err := pr.BaseRepo.IsProtectedBranchForMerging(pr, pr.BaseBranch, doer); err != nil { - return fmt.Errorf("IsProtectedBranch: %v", err) - } else if protected { - return ErrNotAllowedToMerge{ - "The branch is protected", - } - } - - return nil -} - // SetMerged sets a pull request to merged and closes the corresponding issue func (pr *PullRequest) SetMerged() (err error) { if pr.HasMerged { diff --git a/models/repo_permission.go b/models/repo_permission.go index 79d7dd012b..374c6f8d56 100644 --- a/models/repo_permission.go +++ b/models/repo_permission.go @@ -271,7 +271,7 @@ func getUserRepoPermission(e Engine, repo *Repository, user *User) (perm Permiss return } -// IsUserRepoAdmin return ture if user has admin right of a repo +// IsUserRepoAdmin return true if user has admin right of a repo func IsUserRepoAdmin(repo *Repository, user *User) (bool, error) { return isUserRepoAdmin(x, repo, user) } |