summaryrefslogtreecommitdiffstats
path: root/routers/repo/pull.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo/pull.go')
-rw-r--r--routers/repo/pull.go31
1 files changed, 29 insertions, 2 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 6162df9651..9de8268957 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -495,7 +495,7 @@ func ViewPullFiles(ctx *context.Context) {
}
// MergePullRequest response for merging pull request
-func MergePullRequest(ctx *context.Context) {
+func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
issue := checkPullInfo(ctx)
if ctx.Written() {
return
@@ -514,15 +514,42 @@ func MergePullRequest(ctx *context.Context) {
}
return
}
+ pr.Issue = issue
if !pr.CanAutoMerge() || pr.HasMerged {
ctx.Handle(404, "MergePullRequest", nil)
return
}
+ if ctx.HasError() {
+ ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
+ ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
+ return
+ }
+
+ 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
+ }
+
pr.Issue = issue
pr.Issue.Repo = ctx.Repo.Repository
- if err = pr.Merge(ctx.User, ctx.Repo.GitRepo); err != nil {
+ if err = pr.Merge(ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
+ if models.IsErrInvalidMergeStyle(err) {
+ ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
+ ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
+ return
+ }
ctx.Handle(500, "Merge", err)
return
}