Skip to content

Commit 71b5edd

Browse files
committed
fix
1 parent 70eb2f0 commit 71b5edd

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ var migrations = []Migration{
603603
NewMigration("Add index for release sha1", v1_23.AddIndexForReleaseSha1),
604604
// v305 -> v306
605605
NewMigration("Add Repository Licenses", v1_23.AddRepositoryLicenses),
606+
// v306 -> v307
607+
NewMigration("Add Repository Licenses", v1_23.AddBlockAdminMergeOverrideBranchProtection),
606608
}
607609

608610
// GetCurrentDBVersion returns the current db version

options/locale/locale_en-US.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,8 +2461,8 @@ settings.block_on_official_review_requests = Block merge on official review requ
24612461
settings.block_on_official_review_requests_desc = Merging will not be possible when it has official review requests, even if there are enough approvals.
24622462
settings.block_outdated_branch = Block merge if pull request is outdated
24632463
settings.block_outdated_branch_desc = Merging will not be possible when head branch is behind base branch.
2464-
settings.block_admin_merge_override=Administrators must follow branch protection rules
2465-
settings.block_admin_merge_override_desc=Administrators must follow branch protection rules and can not circumvent it.
2464+
settings.block_admin_merge_override = Administrators must follow branch protection rules
2465+
settings.block_admin_merge_override_desc = Administrators must follow branch protection rules and can not circumvent it.
24662466
settings.default_branch_desc = Select a default repository branch for pull requests and code commits:
24672467
settings.merge_style_desc = Merge Styles
24682468
settings.default_merge_style_desc = Default Merge Style

services/pull/check.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const (
6868
)
6969

7070
// CheckPullMergeable check if the pull mergeable based on all conditions (branch protection, merge options, ...)
71-
func CheckPullMergeable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *issues_model.PullRequest, mergeCheckType MergeCheckType, adminSkipProtectionCheck bool) error {
71+
func CheckPullMergeable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *issues_model.PullRequest, mergeCheckType MergeCheckType, adminForceMerge bool) error {
7272
return db.WithTx(stdCtx, func(ctx context.Context) error {
7373
if pr.HasMerged {
7474
return ErrHasMerged
@@ -118,25 +118,21 @@ func CheckPullMergeable(stdCtx context.Context, doer *user_model.User, perm *acc
118118
err = nil
119119
}
120120

121-
// * if the doer is admin, they could sometimes skip the branch protection check
122-
if adminSkipProtectionCheck {
123-
pb, pbErr := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
124-
if pbErr != nil {
125-
return fmt.Errorf("LoadProtectedBranch: %v", err)
121+
// * if admin tries to "Force Merge", they could sometimes skip the branch protection check
122+
if adminForceMerge {
123+
isRepoAdmin, errForceMerge := access_model.IsUserRepoAdmin(ctx, pr.BaseRepo, doer)
124+
if errForceMerge != nil {
125+
return fmt.Errorf("IsUserRepoAdmin failed, repo: %-v, doer: %-v, err: %w", pr.BaseRepo, doer, errForceMerge)
126126
}
127127

128-
isRepoAdmin, errCheckAdmin := access_model.IsUserRepoAdmin(ctx, pr.BaseRepo, doer)
128+
protectedBranchRule, errForceMerge := git_model.GetFirstMatchProtectedBranchRule(ctx, pr.BaseRepoID, pr.BaseBranch)
129+
if errForceMerge != nil {
130+
return fmt.Errorf("GetFirstMatchProtectedBranchRule failed: repo: %-v, base branch: %v, err: %w", pr.BaseRepo, pr.BaseBranch, errForceMerge)
131+
}
129132

130-
/**
131-
* Checks are only skipable if there is no branch protection available or BlockAdminMergeOverride
132-
* of branch protection is set to false
133-
*/
134-
if errCheckAdmin != nil {
135-
log.Error("Unable to check if %-v is a repo admin in %-v: %v", doer, pr.BaseRepo, errCheckAdmin)
136-
return errCheckAdmin
137-
} else if isRepoAdmin && pb != nil && !pb.BlockAdminMergeOverride {
138-
err = nil
139-
} else if isRepoAdmin && pb == nil {
133+
// if doer is admin and the "Force Merge" is not blocked, then clear the branch protection check error
134+
blockAdminForceMerge := protectedBranchRule != nil && protectedBranchRule.BlockAdminMergeOverride
135+
if isRepoAdmin && !blockAdminForceMerge {
140136
err = nil
141137
}
142138
}

0 commit comments

Comments
 (0)