forked from forgejo/forgejo
Prevent merge of outdated PRs on protected branches (#11012)
* Block PR on Outdated Branch * finalize * cleanup * fix typo and sentences thanks @guillep2k Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
parent
2cb5878529
commit
c52d48aae4
15 changed files with 81 additions and 5 deletions
|
@ -574,16 +574,22 @@ func CheckPRReadyToMerge(pr *models.PullRequest) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
if enoughApprovals := pr.ProtectedBranch.HasEnoughApprovals(pr); !enoughApprovals {
|
||||
if !pr.ProtectedBranch.HasEnoughApprovals(pr) {
|
||||
return models.ErrNotAllowedToMerge{
|
||||
Reason: "Does not have enough approvals",
|
||||
}
|
||||
}
|
||||
if rejected := pr.ProtectedBranch.MergeBlockedByRejectedReview(pr); rejected {
|
||||
if pr.ProtectedBranch.MergeBlockedByRejectedReview(pr) {
|
||||
return models.ErrNotAllowedToMerge{
|
||||
Reason: "There are requested changes",
|
||||
}
|
||||
}
|
||||
|
||||
if pr.ProtectedBranch.MergeBlockedByOutdatedBranch(pr) {
|
||||
return models.ErrNotAllowedToMerge{
|
||||
Reason: "The head branch is behind the base branch",
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue