diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index a60a25cdd60..b093b88d9b9 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1242,7 +1242,7 @@ LEVEL = Info ;DELAY_CHECK_FOR_INACTIVE_DAYS = 7 ;; ;; Set the default value for "Delete pull request branch after merge by default" for new repositories -;DEFAULT_DELETE_BRANCH_AFTER_MERGE = false +;DEFAULT_DELETE_BRANCH_AFTER_MERGE = true ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/modules/setting/repository.go b/modules/setting/repository.go index e8ee37a363c..aecd1fec3e9 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -211,6 +211,7 @@ var ( AddCoCommitterTrailers: true, RetargetChildrenOnMerge: true, DelayCheckForInactiveDays: 7, + DefaultDeleteBranchAfterMerge: true, DefaultTitleSource: RepoPRTitleSourceAuto, }, diff --git a/tests/e2e/pull-merge-box.test.ts b/tests/e2e/pull-merge-box.test.ts index 974836fe98d..5f0ae29d029 100644 --- a/tests/e2e/pull-merge-box.test.ts +++ b/tests/e2e/pull-merge-box.test.ts @@ -18,6 +18,6 @@ test('merge box merges a pull request', async ({page, request}) => { await page.getByRole('button', {name: 'Create merge commit'}).click(); await page.locator('form.form-fetch-action').getByRole('button', {name: 'Create merge commit'}).click(); - await expect(page.getByText(/successfully merged/i)).toBeVisible(); + await expect(page.getByText('Merged', {exact: true})).toBeVisible(); await assertNoJsError(page); }); diff --git a/tests/integration/api_pull_test.go b/tests/integration/api_pull_test.go index 4d4746b4dcb..2edb993e38b 100644 --- a/tests/integration/api_pull_test.go +++ b/tests/integration/api_pull_test.go @@ -270,45 +270,36 @@ func TestAPIMergePull(t *testing.T) { t.Run("Normal", func(t *testing.T) { newBranch := "test-pull-1" prDTO := createTestBranchPR(t, newBranch) - performMerge(t, prDTO.Index, map[string]any{"do": "merge"}) + performMerge(t, prDTO.Index, map[string]any{"do": "merge", "delete_branch_after_merge": false}) checkBranchExists(t, newBranch, http.StatusOK) // try to merge again, make sure we cannot perform a merge on the same PR performMerge(t, prDTO.Index, map[string]any{"do": "merge"}, http.StatusMethodNotAllowed) }) - t.Run("DeleteBranchAfterMergePassedByFormField", func(t *testing.T) { + t.Run("DeleteBranchAfterMergeByDefault", func(t *testing.T) { newBranch := "test-pull-2" prDTO := createTestBranchPR(t, newBranch) - performMerge(t, prDTO.Index, map[string]any{"do": "merge", "delete_branch_after_merge": true}) + performMerge(t, prDTO.Index, map[string]any{"do": "merge"}) checkBranchExists(t, newBranch, http.StatusNotFound) }) - updateRepoUnitDefaultDeleteBranchAfterMerge := func(t *testing.T, repo *repo_model.Repository, value bool) { + t.Run("DeleteBranchAfterMergeDisabledByRepoSettings", func(t *testing.T) { prUnit, err := repo.GetUnit(t.Context(), unit_model.TypePullRequests) require.NoError(t, err) - - prUnit.PullRequestsConfig().DefaultDeleteBranchAfterMerge = value + prUnit.PullRequestsConfig().DefaultDeleteBranchAfterMerge = false require.NoError(t, repo_service.UpdateRepositoryUnits(t.Context(), repo, []repo_model.RepoUnit{{ RepoID: repo.ID, Type: unit_model.TypePullRequests, Config: prUnit.PullRequestsConfig(), }}, nil)) - } - t.Run("DeleteBranchAfterMergePassedByRepoSettings", func(t *testing.T) { - newBranch := "test-pull-3" - prDTO := createTestBranchPR(t, newBranch) - updateRepoUnitDefaultDeleteBranchAfterMerge(t, repo, true) - performMerge(t, prDTO.Index, map[string]any{"do": "merge"}) - checkBranchExists(t, newBranch, http.StatusNotFound) - }) + keptPR := createTestBranchPR(t, "test-pull-3") + performMerge(t, keptPR.Index, map[string]any{"do": "merge"}) + checkBranchExists(t, "test-pull-3", http.StatusOK) - t.Run("DeleteBranchAfterMergeFormFieldIsSetButNotRepoSettings", func(t *testing.T) { - newBranch := "test-pull-4" - prDTO := createTestBranchPR(t, newBranch) - updateRepoUnitDefaultDeleteBranchAfterMerge(t, repo, false) - performMerge(t, prDTO.Index, map[string]any{"do": "merge", "delete_branch_after_merge": true}) - checkBranchExists(t, newBranch, http.StatusNotFound) + deletedPR := createTestBranchPR(t, "test-pull-4") + performMerge(t, deletedPR.Index, map[string]any{"do": "merge", "delete_branch_after_merge": true}) + checkBranchExists(t, "test-pull-4", http.StatusNotFound) }) t.Run("SquashMergePreservesFormMessage", func(t *testing.T) { diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index c969d078c66..177abc046f8 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -1215,7 +1215,6 @@ func TestPullSquashMessage(t *testing.T) { user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) user2Session := loginUser(t, user2.Name) - defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultSquashMergeMessage, "COMMIT_MESSAGES")() defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultMergeMessageSize, 80)() repo, err := repo_service.CreateRepository(t.Context(), user2, user2, repo_service.CreateRepoOptions{ @@ -1226,6 +1225,14 @@ func TestPullSquashMessage(t *testing.T) { DefaultBranch: "main", }) require.NoError(t, err) + prUnit, err := repo.GetUnit(t.Context(), unit_model.TypePullRequests) + require.NoError(t, err) + prUnit.PullRequestsConfig().DefaultSquashMergeMessage = repo_model.SquashMergeMessageCommitMessages + require.NoError(t, repo_service.UpdateRepositoryUnits(t.Context(), repo, []repo_model.RepoUnit{{ + RepoID: repo.ID, + Type: unit_model.TypePullRequests, + Config: prUnit.PullRequestsConfig(), + }}, nil)) type commitInfo struct { userName string @@ -1352,8 +1359,6 @@ Co-authored-by: user4 pullRequest.Issue.Content = "PR description" pullRequest.BaseRepo = repo - prUnit, err := repo.GetUnit(t.Context(), unit_model.TypePullRequests) - require.NoError(t, err) for style, expected := range map[repo_model.SquashMergeMessage]string{ repo_model.SquashMergeMessageBlank: "", repo_model.SquashMergeMessagePRBody: "PR description", @@ -1366,7 +1371,6 @@ Co-authored-by: user4 }) t.Run("API squash merge without message uses repository default", func(t *testing.T) { - defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultSquashMergeMessage, "PR_BODY")() token := getTokenForLoggedInUser(t, user2Session, auth_model.AccessTokenScopeWriteRepository) req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/pulls/1/merge", user2.Name, repo.Name), map[string]string{"do": "squash"}).AddTokenAuth(token) MakeRequest(t, req, http.StatusOK)