diff options
Diffstat (limited to 'routers/api/v1/repo/pull.go')
-rw-r--r-- | routers/api/v1/repo/pull.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 50b864e323..7e011219be 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -434,7 +435,7 @@ func IsPullRequestMerged(ctx *context.APIContext) { } // MergePullRequest merges a PR given an index -func MergePullRequest(ctx *context.APIContext) { +func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) { // swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/merge repository repoMergePullRequest // --- // summary: Merge a pull request @@ -497,7 +498,30 @@ func MergePullRequest(ctx *context.APIContext) { return } - if err := pr.Merge(ctx.User, ctx.Repo.GitRepo); err != nil { + if len(form.Do) == 0 { + form.Do = string(models.MergeStyleMerge) + } + + message := strings.TrimSpace(form.MergeTitleField) + if len(message) == 0 { + if models.MergeStyle(form.Do) == models.MergeStyleMerge { + message = pr.GetDefaultMergeMessage() + } + if models.MergeStyle(form.Do) == models.MergeStyleSquash { + message = pr.GetDefaultSquashMessage() + } + } + + form.MergeMessageField = strings.TrimSpace(form.MergeMessageField) + if len(form.MergeMessageField) > 0 { + message += "\n\n" + form.MergeMessageField + } + + if err := pr.Merge(ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil { + if models.IsErrInvalidMergeStyle(err) { + ctx.Status(405) + return + } ctx.Error(500, "Merge", err) return } |