summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorJulien Tant <julien@craftyx.fr>2018-08-13 21:04:39 +0200
committerLauris BH <lauris@nix.lv>2018-08-13 22:04:39 +0300
commit7781e8cef2dfe73d71be7804f4c5a7c5f1995d31 (patch)
tree7bbe6d2a031655478538e152912182f5ad3500eb /routers
parent52c2cb15db77a381880db7e44f133a49b3516dd5 (diff)
downloadgitea-7781e8cef2dfe73d71be7804f4c5a7c5f1995d31.tar.gz
gitea-7781e8cef2dfe73d71be7804f4c5a7c5f1995d31.zip
Disable merging a WIP Pull request (#4529)
* prevent pull request to be merged when PR is a WIP * add tests * add helper to prepend WIP: in PR title * move default wip prefixes into settings * use configurable WIP prefixes in javascript and default to first one in templates * add documentation * add unit test on pull model Signed-off-by: Julien Tant <julien@craftyx.fr>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/pull.go2
-rw-r--r--routers/repo/issue.go2
-rw-r--r--routers/repo/pull.go14
3 files changed, 17 insertions, 1 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index c346d81e33..1527b8e8c9 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -510,7 +510,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
return
}
- if !pr.CanAutoMerge() || pr.HasMerged {
+ if !pr.CanAutoMerge() || pr.HasMerged || pr.IsWorkInProgress() {
ctx.Status(405)
return
}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 585d2f67ba..3cce483062 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -356,6 +356,7 @@ func NewIssue(ctx *context.Context) {
ctx.Data["RequireHighlightJS"] = true
ctx.Data["RequireSimpleMDE"] = true
ctx.Data["RequireTribute"] = true
+ ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
setTemplateIfExists(ctx, issueTemplateKey, IssueTemplateCandidates)
renderAttachmentSettings(ctx)
@@ -449,6 +450,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
ctx.Data["RequireHighlightJS"] = true
ctx.Data["RequireSimpleMDE"] = true
ctx.Data["ReadOnly"] = false
+ ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
renderAttachmentSettings(ctx)
var (
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index e6592e1f57..6a1aaf314d 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -323,6 +323,12 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq
ctx.ServerError("GetPullRequestInfo", err)
return nil
}
+
+ if pull.IsWorkInProgress() {
+ ctx.Data["IsPullWorkInProgress"] = true
+ ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix()
+ }
+
ctx.Data["NumCommits"] = prInfo.Commits.Len()
ctx.Data["NumFiles"] = prInfo.NumFiles
return prInfo
@@ -516,6 +522,12 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return
}
+ if pr.IsWorkInProgress() {
+ ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_wip"))
+ ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
+ return
+ }
+
if ctx.HasError() {
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
@@ -747,6 +759,7 @@ func CompareAndPullRequest(ctx *context.Context) {
ctx.Data["IsDiffCompare"] = true
ctx.Data["RequireHighlightJS"] = true
ctx.Data["RequireTribute"] = true
+ ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates)
renderAttachmentSettings(ctx)
@@ -790,6 +803,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
ctx.Data["PageIsComparePull"] = true
ctx.Data["IsDiffCompare"] = true
ctx.Data["RequireHighlightJS"] = true
+ ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
renderAttachmentSettings(ctx)
var (