|
|
|
@@ -44,6 +44,7 @@ type ProtectedBranch struct { |
|
|
|
ApprovalsWhitelistUserIDs []int64 `xorm:"JSON TEXT"` |
|
|
|
ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"` |
|
|
|
RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"` |
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"created"` |
|
|
|
UpdatedUnix timeutil.TimeStamp `xorm:"updated"` |
|
|
|
} |
|
|
|
@@ -166,6 +167,23 @@ func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(pr *PullRequest) |
|
|
|
return approvals |
|
|
|
} |
|
|
|
|
|
|
|
// MergeBlockedByRejectedReview returns true if merge is blocked by rejected reviews |
|
|
|
func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(pr *PullRequest) bool { |
|
|
|
if !protectBranch.BlockOnRejectedReviews { |
|
|
|
return false |
|
|
|
} |
|
|
|
rejectExist, err := x.Where("issue_id = ?", pr.IssueID). |
|
|
|
And("type = ?", ReviewTypeReject). |
|
|
|
And("official = ?", true). |
|
|
|
Exist(new(Review)) |
|
|
|
if err != nil { |
|
|
|
log.Error("MergeBlockedByRejectedReview: %v", err) |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
return rejectExist |
|
|
|
} |
|
|
|
|
|
|
|
// GetProtectedBranchByRepoID getting protected branch by repo ID |
|
|
|
func GetProtectedBranchByRepoID(repoID int64) ([]*ProtectedBranch, error) { |
|
|
|
protectedBranches := make([]*ProtectedBranch, 0) |
|
|
|
@@ -340,7 +358,7 @@ func (repo *Repository) IsProtectedBranchForMerging(pr *PullRequest, branchName |
|
|
|
if err != nil { |
|
|
|
return true, err |
|
|
|
} else if has { |
|
|
|
return !protectedBranch.CanUserMerge(doer.ID) || !protectedBranch.HasEnoughApprovals(pr), nil |
|
|
|
return !protectedBranch.CanUserMerge(doer.ID) || !protectedBranch.HasEnoughApprovals(pr) || protectedBranch.MergeBlockedByRejectedReview(pr), nil |
|
|
|
} |
|
|
|
|
|
|
|
return false, nil |
|
|
|
|