diff options
author | a1012112796 <1012112796@qq.com> | 2021-03-04 11:41:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-03 22:41:23 -0500 |
commit | a5279b74b63248902a6572df5afa3745367e6cb9 (patch) | |
tree | 7f1fac744013b533bfb0580d48a27d0aae5ab04e /routers/api/v1/repo | |
parent | 523efa433b61e00e7a14bd31cac315e43842d729 (diff) | |
download | gitea-a5279b74b63248902a6572df5afa3745367e6cb9.tar.gz gitea-a5279b74b63248902a6572df5afa3745367e6cb9.zip |
Make manual merge autodetection optional and add manual merge as merge method (#12543)
* Make auto check manual merge as a chooseable mod and add manual merge way on ui
as title, Before this pr, we use same way with GH to check manually merge.
It good, but in some special cases, misjudgments can occur. and it's hard
to fix this bug. So I add option to allow repo manager block "auto check manual merge"
function, Then it will have same style like gitlab(allow empty pr). and to compensate for
not being able to detect THE PR merge automatically, I added a manual approach.
Signed-off-by: a1012112796 <1012112796@qq.com>
* make swager
* api support
* ping ci
* fix TestPullCreate_EmptyChangesWithCommits
* Apply suggestions from code review
Co-authored-by: zeripath <art27@cantab.net>
* Apply review suggestions and add test
* Apply suggestions from code review
Co-authored-by: zeripath <art27@cantab.net>
* fix build
* test error message
* make fmt
* Fix indentation issues identified by @silverwind
Co-authored-by: silverwind <me@silverwind.io>
* Fix tests and make manually merged disabled error on API the same
Signed-off-by: Andrew Thornton <art27@cantab.net>
* a small nit
* fix wrong commit id error
* fix bug
* simple test
* fix test
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r-- | routers/api/v1/repo/pull.go | 26 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 8 |
2 files changed, 30 insertions, 4 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 38dac36553..8eda949652 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -769,13 +769,31 @@ func MergePullRequest(ctx *context.APIContext) { return } - if !pr.CanAutoMerge() { - ctx.Error(http.StatusMethodNotAllowed, "PR not in mergeable state", "Please try again later") + if pr.HasMerged { + ctx.Error(http.StatusMethodNotAllowed, "PR already merged", "") return } - if pr.HasMerged { - ctx.Error(http.StatusMethodNotAllowed, "PR already merged", "") + // handle manually-merged mark + if models.MergeStyle(form.Do) == models.MergeStyleManuallyMerged { + if err = pull_service.MergedManually(pr, ctx.User, 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", models.MergeStyle(form.Do))) + return + } + if strings.Contains(err.Error(), "Wrong commit ID") { + ctx.JSON(http.StatusConflict, err) + return + } + ctx.Error(http.StatusInternalServerError, "Manually-Merged", err) + return + } + ctx.Status(http.StatusOK) + return + } + + if !pr.CanAutoMerge() { + ctx.Error(http.StatusMethodNotAllowed, "PR not in mergeable state", "Please try again later") return } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index b84c5993e4..b12797f83b 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -725,6 +725,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, + AllowManualMerge: true, + AutodetectManualMerge: false, } } else { config = unit.PullRequestsConfig() @@ -745,6 +747,12 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { if opts.AllowSquash != nil { config.AllowSquash = *opts.AllowSquash } + if opts.AllowManualMerge != nil { + config.AllowManualMerge = *opts.AllowManualMerge + } + if opts.AutodetectManualMerge != nil { + config.AutodetectManualMerge = *opts.AutodetectManualMerge + } units = append(units, models.RepoUnit{ RepoID: repo.ID, |