Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent merge of outdated PRs on protected branches #11012

Merged
merged 13 commits into from
Apr 17, 2020
Merged
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
6543 committed Apr 14, 2020
commit 005843ed4d8f1d92d0b48bc7ce3bfedb933a6c1f
8 changes: 1 addition & 7 deletions models/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,7 @@ func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(pr *PullReque

// MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch
func (protectBranch *ProtectedBranch) MergeBlockedByOutdatedBranch(pr *PullRequest) bool {
if !protectBranch.BlockOnOutdatedBranch {
return false
}
if pr.CommitsBehind == 0 {
return false
}
return true
return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0
}

// GetProtectedFilePatterns parses a semicolon separated list of protected file patterns and returns a glob.Glob slice
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ pulls.is_checking = "Merge conflict checking is in progress. Try again in few mo
pulls.required_status_check_failed = Some required checks were not successful.
pulls.required_status_check_administrator = As an administrator, you may still merge this pull request.
pulls.blocked_by_approvals = "This Pull Request doesn't have enough approvals yet. %d of %d approvals granted."
pulls.blocked_by_rejection = "This Pull Request has an outdated head branch."
pulls.blocked_by_rejection = "This Pull Request has changes requested by an official reviewer."
pulls.blocked_by_outdated_branch = "This Pull Request is blocked by an outdated head branch."
6543 marked this conversation as resolved.
Show resolved Hide resolved
pulls.can_auto_merge_desc = This pull request can be merged automatically.
pulls.cannot_auto_merge_desc = This pull request cannot be merged automatically due to conflicts.
Expand Down
2 changes: 1 addition & 1 deletion services/pull/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func CheckPRReadyToMerge(pr *models.PullRequest) (err error) {

if pr.ProtectedBranch.MergeBlockedByOutdatedBranch(pr) {
return models.ErrNotAllowedToMerge{
Reason: fmt.Sprintf("There head branch %d behind base branch", pr.CommitsBehind),
Reason: fmt.Sprintf("Head branch %d behind base branch", pr.CommitsBehind),
6543 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down