summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2018-01-05 20:56:50 +0200
committerGitHub <noreply@github.com>2018-01-05 20:56:50 +0200
commit8ac1501ad7f8b350bd9c1bf01b25f994fd3560f9 (patch)
treecf9b661996134da3e39aa6ddd2af4e13f7dbf30f /routers/api/v1
parenta192f3052ed9b59d1404fdcebf2b5c156d6d6969 (diff)
downloadgitea-8ac1501ad7f8b350bd9c1bf01b25f994fd3560f9.tar.gz
gitea-8ac1501ad7f8b350bd9c1bf01b25f994fd3560f9.zip
Add Pull Request merge options - Ignore white-space for conflict checking, Rebase, Squash merge (#3188)
* Pull request options migration and UI in settings * Add ignore whitespace functionality * Fix settings if pull requests are disabled * Fix migration transaction * Merge with Rebase functionality * UI changes and related functionality for pull request merging button * Implement squash functionality * Fix rebase merging * Fix pull request merge tests * Add squash and rebase tests * Fix API method to reuse default message functions * Some refactoring and small fixes * Remove more hardcoded values from tests * Remove unneeded check from API method * Fix variable name and comment typo * Fix reset commit count after PR merge
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/api.go2
-rw-r--r--routers/api/v1/repo/pull.go28
2 files changed, 27 insertions, 3 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 588a763616..8a300f9958 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -477,7 +477,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("").Get(repo.GetPullRequest).
Patch(reqToken(), reqRepoWriter(), bind(api.EditPullRequestOption{}), repo.EditPullRequest)
m.Combo("/merge").Get(repo.IsPullRequestMerged).
- Post(reqToken(), reqRepoWriter(), repo.MergePullRequest)
+ Post(reqToken(), reqRepoWriter(), bind(auth.MergePullRequestForm{}), repo.MergePullRequest)
})
}, mustAllowPulls, context.ReferencesGitRepo())
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
}