Search in sources :

Example 36 with ChangeMessageInfo

use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.

the class CreateMergePatchSetIT method createMergePatchSet_ConflictAllowed.

@Test
public void createMergePatchSet_ConflictAllowed() throws Exception {
    RevCommit initialHead = projectOperations.project(project).getHead("master");
    createBranch(BranchNameKey.create(project, "dev"));
    // create a change for master
    String changeId = createChange().getChangeId();
    String fileName = "shared.txt";
    String sourceSubject = "source change";
    String sourceContent = "source content";
    String targetSubject = "target change";
    String targetContent = "target content";
    testRepo.reset(initialHead);
    PushOneCommit.Result currentMaster = pushFactory.create(admin.newIdent(), testRepo, targetSubject, fileName, targetContent).to("refs/heads/master");
    currentMaster.assertOkStatus();
    String parent = currentMaster.getCommit().getName();
    // push a commit into dev branch
    testRepo.reset(initialHead);
    PushOneCommit.Result changeA = pushFactory.create(user.newIdent(), testRepo, sourceSubject, fileName, sourceContent).to("refs/heads/dev");
    changeA.assertOkStatus();
    MergeInput mergeInput = new MergeInput();
    mergeInput.source = "dev";
    mergeInput.allowConflicts = true;
    MergePatchSetInput in = new MergePatchSetInput();
    in.merge = mergeInput;
    in.subject = "update change by merge ps2";
    TestWorkInProgressStateChangedListener wipStateChangedListener = new TestWorkInProgressStateChangedListener();
    try (ExtensionRegistry.Registration registration = extensionRegistry.newRegistration().add(wipStateChangedListener)) {
        ChangeInfo changeInfo = gApi.changes().id(changeId).createMergePatchSet(in);
        assertThat(changeInfo.subject).isEqualTo(in.subject);
        assertThat(changeInfo.containsGitConflicts).isTrue();
        assertThat(changeInfo.workInProgress).isTrue();
    }
    assertThat(wipStateChangedListener.invoked).isTrue();
    assertThat(wipStateChangedListener.wip).isTrue();
    // To get the revisions, we must retrieve the change with more change options.
    ChangeInfo changeInfo = gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
    assertThat(changeInfo.revisions).hasSize(2);
    assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit).isEqualTo(parent);
    // Verify that the file content in the created patch set is correct.
    // We expect that it has conflict markers to indicate the conflict.
    BinaryResult bin = gApi.changes().id(changeId).current().file(fileName).content();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    bin.writeTo(os);
    String fileContent = new String(os.toByteArray(), UTF_8);
    String sourceSha1 = abbreviateName(changeA.getCommit(), 6);
    String targetSha1 = abbreviateName(currentMaster.getCommit(), 6);
    assertThat(fileContent).isEqualTo("<<<<<<< TARGET BRANCH (" + targetSha1 + " " + targetSubject + ")\n" + targetContent + "\n" + "=======\n" + sourceContent + "\n" + ">>>>>>> SOURCE BRANCH (" + sourceSha1 + " " + sourceSubject + ")\n");
    // Verify the message that has been posted on the change.
    List<ChangeMessageInfo> messages = gApi.changes().id(changeId).messages();
    assertThat(messages).hasSize(2);
    assertThat(Iterables.getLast(messages).message).isEqualTo("Uploaded patch set 2.\n\n" + "The following files contain Git conflicts:\n" + "* " + fileName + "\n");
}
Also used : MergeInput(com.google.gerrit.extensions.common.MergeInput) MergePatchSetInput(com.google.gerrit.extensions.common.MergePatchSetInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) RevCommit(org.eclipse.jgit.revwalk.RevCommit) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 37 with ChangeMessageInfo

use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.

the class ChangeIT method rebaseConflict_conflictsAllowed.

@Test
public void rebaseConflict_conflictsAllowed() throws Exception {
    String patchSetSubject = "patch set change";
    String patchSetContent = "patch set content";
    String baseSubject = "base change";
    String baseContent = "base content";
    PushOneCommit.Result r1 = createChange(baseSubject, PushOneCommit.FILE_NAME, baseContent);
    gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).review(ReviewInput.approve());
    gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).submit();
    testRepo.reset("HEAD~1");
    PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, patchSetSubject, PushOneCommit.FILE_NAME, patchSetContent);
    PushOneCommit.Result r2 = push.to("refs/for/master");
    r2.assertOkStatus();
    String changeId = r2.getChangeId();
    RevCommit patchSet = r2.getCommit();
    RevCommit base = r1.getCommit();
    TestWorkInProgressStateChangedListener wipStateChangedListener = new TestWorkInProgressStateChangedListener();
    try (Registration registration = extensionRegistry.newRegistration().add(wipStateChangedListener)) {
        RebaseInput rebaseInput = new RebaseInput();
        rebaseInput.allowConflicts = true;
        ChangeInfo changeInfo = gApi.changes().id(changeId).revision(patchSet.name()).rebaseAsInfo(rebaseInput);
        assertThat(changeInfo.containsGitConflicts).isTrue();
        assertThat(changeInfo.workInProgress).isTrue();
    }
    assertThat(wipStateChangedListener.invoked).isTrue();
    assertThat(wipStateChangedListener.wip).isTrue();
    // To get the revisions, we must retrieve the change with more change options.
    ChangeInfo changeInfo = gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
    assertThat(changeInfo.revisions).hasSize(2);
    assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit).isEqualTo(base.name());
    // Verify that the file content in the created patch set is correct.
    // We expect that it has conflict markers to indicate the conflict.
    BinaryResult bin = gApi.changes().id(changeId).current().file(PushOneCommit.FILE_NAME).content();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    bin.writeTo(os);
    String fileContent = new String(os.toByteArray(), UTF_8);
    String patchSetSha1 = abbreviateName(patchSet, 6);
    String baseSha1 = abbreviateName(base, 6);
    assertThat(fileContent).isEqualTo("<<<<<<< PATCH SET (" + patchSetSha1 + " " + patchSetSubject + ")\n" + patchSetContent + "\n" + "=======\n" + baseContent + "\n" + ">>>>>>> BASE      (" + baseSha1 + " " + baseSubject + ")\n");
    // Verify the message that has been posted on the change.
    List<ChangeMessageInfo> messages = gApi.changes().id(changeId).messages();
    assertThat(messages).hasSize(2);
    assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 2: Patch Set 1 was rebased\n\n" + "The following files contain Git conflicts:\n" + "* " + PushOneCommit.FILE_NAME + "\n");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 38 with ChangeMessageInfo

use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.

the class ListMailFilterIT method listFilterAllowFiltersNotListedUser.

@Test
@GerritConfig(name = "receiveemail.filter.mode", value = "ALLOW")
@GerritConfig(name = "receiveemail.filter.patterns", values = { ".+@gerritcodereview\\.com", "a@b\\.com" })
public void listFilterAllowFiltersNotListedUser() throws Exception {
    ChangeInfo changeInfo = createChangeAndReplyByEmail();
    // Check that the comments from the email have NOT been persisted
    Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
    assertThat(messages).hasSize(2);
    // Check that no emails were sent because of this error
    assertThat(sender.getMessages()).isEmpty();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test)

Example 39 with ChangeMessageInfo

use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.

the class ListMailFilterIT method listFilterBlockDoesNotFilterNotListedUser.

@Test
@GerritConfig(name = "receiveemail.filter.mode", value = "BLOCK")
@GerritConfig(name = "receiveemail.filter.patterns", values = { ".+@gerritcodereview\\.com", "a@b\\.com" })
public void listFilterBlockDoesNotFilterNotListedUser() throws Exception {
    ChangeInfo changeInfo = createChangeAndReplyByEmail();
    // Check that the comments from the email have been persisted
    Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
    assertThat(messages).hasSize(3);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test)

Example 40 with ChangeMessageInfo

use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.

the class ListMailFilterIT method listFilterAllowDoesNotFilterListedUser.

@Test
@GerritConfig(name = "receiveemail.filter.mode", value = "ALLOW")
@GerritConfig(name = "receiveemail.filter.patterns", values = { ".+ser1@example\\.com", "a@b\\.com" })
public void listFilterAllowDoesNotFilterListedUser() throws Exception {
    ChangeInfo changeInfo = createChangeAndReplyByEmail();
    // Check that the comments from the email have been persisted
    Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
    assertThat(messages).hasSize(3);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test)

Aggregations

ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)75 Test (org.junit.Test)61 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)47 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)47 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)37 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)13 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)10 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)10 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)9 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)8 ArrayList (java.util.ArrayList)8 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)6 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)5 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)5 CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)5 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 List (java.util.List)5 Change (com.google.gerrit.entities.Change)4