diff options
author | Jason Song | 2023-02-21 22:42:07 +0800 |
---|---|---|
committer | GitHub | 2023-02-21 08:42:07 -0600 |
commit | c8c2a31818527f7377ddb9fb111a55d0c058ebe7 (patch) | |
tree | 5ebb1653b112dbf66e00d9ec34755382cfd5c6cf /routers | |
parent | 1fcf96ad0166420cbdb013365ecae42e3537b42a (diff) |
Add force_merge to merge request and fix checking mergable (#23010)
Fix #23000.
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/pull.go | 15 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 16 |
2 files changed, 23 insertions, 8 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index fa8b517ae..84eebeb94 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -767,11 +767,18 @@ func MergePullRequest(ctx *context.APIContext) { } } - manuallMerge := repo_model.MergeStyle(form.Do) == repo_model.MergeStyleManuallyMerged - force := form.ForceMerge != nil && *form.ForceMerge + manuallyMerged := repo_model.MergeStyle(form.Do) == repo_model.MergeStyleManuallyMerged + + mergeCheckType := pull_service.MergeCheckTypeGeneral + if form.MergeWhenChecksSucceed { + mergeCheckType = pull_service.MergeCheckTypeAuto + } + if manuallyMerged { + mergeCheckType = pull_service.MergeCheckTypeManually + } // start with merging by checking - if err := pull_service.CheckPullMergable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, manuallMerge, force); err != nil { + if err := pull_service.CheckPullMergable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, mergeCheckType, form.ForceMerge); err != nil { if errors.Is(err, pull_service.ErrIsClosed) { ctx.NotFound() } else if errors.Is(err, pull_service.ErrUserNotAllowedToMerge) { @@ -793,7 +800,7 @@ func MergePullRequest(ctx *context.APIContext) { } // handle manually-merged mark - if manuallMerge { + if manuallyMerged { if err := pull_service.MergedManually(pr, ctx.Doer, ctx.Repo.GitRepo, form.MergeCommitID); err != nil { if models.IsErrInvalidMergeStyle(err) { ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do))) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index c7a59da8a..38b9f22cb 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -926,11 +926,19 @@ func MergePullRequest(ctx *context.Context) { pr := issue.PullRequest pr.Issue = issue pr.Issue.Repo = ctx.Repo.Repository - manualMerge := repo_model.MergeStyle(form.Do) == repo_model.MergeStyleManuallyMerged - forceMerge := form.ForceMerge != nil && *form.ForceMerge + + manuallyMerged := repo_model.MergeStyle(form.Do) == repo_model.MergeStyleManuallyMerged + + mergeCheckType := pull_service.MergeCheckTypeGeneral + if form.MergeWhenChecksSucceed { + mergeCheckType = pull_service.MergeCheckTypeAuto + } + if manuallyMerged { + mergeCheckType = pull_service.MergeCheckTypeManually + } // start with merging by checking - if err := pull_service.CheckPullMergable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, manualMerge, forceMerge); err != nil { + if err := pull_service.CheckPullMergable(ctx, ctx.Doer, &ctx.Repo.Permission, pr, mergeCheckType, form.ForceMerge); err != nil { switch { case errors.Is(err, pull_service.ErrIsClosed): if issue.IsPull { @@ -962,7 +970,7 @@ func MergePullRequest(ctx *context.Context) { } // handle manually-merged mark - if manualMerge { + if manuallyMerged { if err := pull_service.MergedManually(pr, ctx.Doer, ctx.Repo.GitRepo, form.MergeCommitID); err != nil { switch { |