summaryrefslogtreecommitdiffstats
path: root/integrations/pull_merge_test.go
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2022-04-21 21:55:45 +0000
committerGitHub <noreply@github.com>2022-04-21 22:55:45 +0100
commitebe569a268bbe71bf2bc30cd2829227700688b57 (patch)
treee4ba88d01dbaaee73135b8f61f52ae78487c0383 /integrations/pull_merge_test.go
parent3ec1b6c2238c9eb46709091567eb2564aec86d99 (diff)
downloadgitea-ebe569a268bbe71bf2bc30cd2829227700688b57.tar.gz
gitea-ebe569a268bbe71bf2bc30cd2829227700688b57.zip
Set correct PR status on 3way on conflict checking (#19457)
* Set correct PR status on 3way on conflict checking - When 3-way merge is enabled for conflict checking, it has a new interesting behavior that it doesn't return any error when it found a conflict, so we change the condition to not check for the error, but instead check if conflictedfiles is populated, this fixes a issue whereby PR status wasn't correctly on conflicted PR's. - Refactor the mergeable property(which was incorrectly set and lead me this bug) to be more maintainable. - Add a dedicated test for conflicting checking, so it should prevent future issues with this. * Fix linter
Diffstat (limited to 'integrations/pull_merge_test.go')
-rw-r--r--integrations/pull_merge_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go
index d7cb042e9c..f8e8c79a88 100644
--- a/integrations/pull_merge_test.go
+++ b/integrations/pull_merge_test.go
@@ -26,6 +26,8 @@ import (
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/translation/i18n"
"code.gitea.io/gitea/services/pull"
+ repo_service "code.gitea.io/gitea/services/repository"
+ files_service "code.gitea.io/gitea/services/repository/files"
"github.com/stretchr/testify/assert"
)
@@ -346,3 +348,74 @@ func TestCantMergeUnrelated(t *testing.T) {
gitRepo.Close()
})
}
+
+func TestConflictChecking(t *testing.T) {
+ onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
+
+ // Create new clean repo to test conflict checking.
+ baseRepo, err := repo_service.CreateRepository(user, user, models.CreateRepoOptions{
+ Name: "conflict-checking",
+ Description: "Tempo repo",
+ AutoInit: true,
+ Readme: "Default",
+ DefaultBranch: "main",
+ })
+ assert.NoError(t, err)
+ assert.NotEmpty(t, baseRepo)
+
+ // create a commit on new branch.
+ _, err = files_service.CreateOrUpdateRepoFile(git.DefaultContext, baseRepo, user, &files_service.UpdateRepoFileOptions{
+ TreePath: "important_file",
+ Message: "Add a important file",
+ Content: "Just a non-important file",
+ IsNewFile: true,
+ OldBranch: "main",
+ NewBranch: "important-secrets",
+ })
+ assert.NoError(t, err)
+
+ // create a commit on main branch.
+ _, err = files_service.CreateOrUpdateRepoFile(git.DefaultContext, baseRepo, user, &files_service.UpdateRepoFileOptions{
+ TreePath: "important_file",
+ Message: "Add a important file",
+ Content: "Not the same content :P",
+ IsNewFile: true,
+ OldBranch: "main",
+ NewBranch: "main",
+ })
+ assert.NoError(t, err)
+
+ // create Pull to merge the important-secrets branch into main branch.
+ pullIssue := &models.Issue{
+ RepoID: baseRepo.ID,
+ Title: "PR with conflict!",
+ PosterID: user.ID,
+ Poster: user,
+ IsPull: true,
+ }
+
+ pullRequest := &models.PullRequest{
+ HeadRepoID: baseRepo.ID,
+ BaseRepoID: baseRepo.ID,
+ HeadBranch: "important-secrets",
+ BaseBranch: "main",
+ HeadRepo: baseRepo,
+ BaseRepo: baseRepo,
+ Type: models.PullRequestGitea,
+ }
+ err = pull.NewPullRequest(git.DefaultContext, baseRepo, pullIssue, nil, nil, pullRequest, nil)
+ assert.NoError(t, err)
+
+ issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{Title: "PR with conflict!"}).(*models.Issue)
+ conflictingPR, err := models.GetPullRequestByIssueID(issue.ID)
+ assert.NoError(t, err)
+
+ // Ensure conflictedFiles is populated.
+ assert.Equal(t, 1, len(conflictingPR.ConflictedFiles))
+ // Check if status is correct.
+ assert.Equal(t, models.PullRequestStatusConflict, conflictingPR.Status)
+ // Ensure that mergeable returns false
+ assert.False(t, conflictingPR.Mergeable())
+ })
+}