diff options
author | Julien Tant <julien@craftyx.fr> | 2018-08-13 21:04:39 +0200 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-08-13 22:04:39 +0300 |
commit | 7781e8cef2dfe73d71be7804f4c5a7c5f1995d31 (patch) | |
tree | 7bbe6d2a031655478538e152912182f5ad3500eb /integrations/api_pull_test.go | |
parent | 52c2cb15db77a381880db7e44f133a49b3516dd5 (diff) | |
download | gitea-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 'integrations/api_pull_test.go')
-rw-r--r-- | integrations/api_pull_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/integrations/api_pull_test.go b/integrations/api_pull_test.go index b9bab920e1..e56b91d8b9 100644 --- a/integrations/api_pull_test.go +++ b/integrations/api_pull_test.go @@ -5,10 +5,13 @@ package integrations import ( + "fmt" "net/http" "testing" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/auth" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/sdk/gitea" "github.com/stretchr/testify/assert" @@ -28,3 +31,26 @@ func TestAPIViewPulls(t *testing.T) { expectedLen := models.GetCount(t, &models.Issue{RepoID: repo.ID}, models.Cond("is_pull = ?", true)) assert.Len(t, pulls, expectedLen) } + +// TestAPIMergePullWIP ensures that we can't merge a WIP pull request +func TestAPIMergePullWIP(t *testing.T) { + prepareTestEnv(t) + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User) + pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{Status: models.PullRequestStatusMergeable}, models.Cond("has_merged = ?", false)).(*models.PullRequest) + pr.LoadIssue() + pr.Issue.ChangeTitle(owner, setting.Repository.PullRequest.WorkInProgressPrefixes[0]+" "+pr.Issue.Title) + + // force reload + pr.LoadAttributes() + + assert.Contains(t, pr.Issue.Title, setting.Repository.PullRequest.WorkInProgressPrefixes[0]) + + session := loginUser(t, owner.Name) + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge", owner.Name, repo.Name, pr.Index), &auth.MergePullRequestForm{ + MergeMessageField: pr.Issue.Title, + Do: string(models.MergeStyleMerge), + }) + + session.MakeRequest(t, req, http.StatusMethodNotAllowed) +} |