Search in sources :

Example 46 with ChangeMessageInfo

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

the class PostReviewIT method extendChangeMessageFromPlugin.

@Test
public void extendChangeMessageFromPlugin() throws Exception {
    PushOneCommit.Result r = createChange();
    String testMessage = "hello from plugin";
    TestOnPostReview testOnPostReview = new TestOnPostReview(testMessage);
    try (Registration registration = extensionRegistry.newRegistration().add(testOnPostReview)) {
        ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
        gApi.changes().id(r.getChangeId()).current().review(input);
        Collection<ChangeMessageInfo> messages = gApi.changes().id(r.getChangeId()).get().messages;
        assertThat(Iterables.getLast(messages).message).isEqualTo(String.format("Patch Set 1: Code-Review+1\n\n%s\n", testMessage));
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 47 with ChangeMessageInfo

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

the class PostReviewIT method extendChangeMessageFromMultiplePlugins.

@Test
public void extendChangeMessageFromMultiplePlugins() throws Exception {
    PushOneCommit.Result r = createChange();
    String testMessage1 = "hello from plugin 1";
    String testMessage2 = "message from plugin 2";
    TestOnPostReview testOnPostReview1 = new TestOnPostReview(testMessage1);
    TestOnPostReview testOnPostReview2 = new TestOnPostReview(testMessage2);
    try (Registration registration = extensionRegistry.newRegistration().add(testOnPostReview1).add(testOnPostReview2)) {
        ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
        gApi.changes().id(r.getChangeId()).current().review(input);
        Collection<ChangeMessageInfo> messages = gApi.changes().id(r.getChangeId()).get().messages;
        assertThat(Iterables.getLast(messages).message).isEqualTo(String.format("Patch Set 1: Code-Review+1\n\n%s\n\n%s\n", testMessage1, testMessage2));
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 48 with ChangeMessageInfo

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

the class PostReviewIT method validateCommentsInChangeMessage_messageOK.

@Test
public void validateCommentsInChangeMessage_messageOK() throws Exception {
    PushOneCommit.Result r = createChange();
    when(mockCommentValidator.validateComments(eq(contextFor(r)), captor.capture())).thenReturn(ImmutableList.of());
    ReviewInput input = new ReviewInput().message(COMMENT_TEXT);
    int numMessages = gApi.changes().id(r.getChangeId()).get().messages.size();
    gApi.changes().id(r.getChangeId()).current().review(input);
    assertValidatorCalledWith(CHANGE_MESSAGE_FOR_VALIDATION);
    assertThat(gApi.changes().id(r.getChangeId()).get().messages).hasSize(numMessages + 1);
    ChangeMessageInfo message = Iterables.getLast(gApi.changes().id(r.getChangeId()).get().messages);
    assertThat(message.message).contains(COMMENT_TEXT);
}
Also used : ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 49 with ChangeMessageInfo

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

the class CreateMergePatchSetIT method createMergePatchSet.

@Test
public void createMergePatchSet() throws Exception {
    RevCommit initialHead = projectOperations.project(project).getHead("master");
    createBranch(BranchNameKey.create(project, "dev"));
    // create a change for master
    String changeId = createChange().getChangeId();
    testRepo.reset(initialHead);
    PushOneCommit.Result currentMaster = pushTo("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, "change A", "A.txt", "A content").to("refs/heads/dev");
    changeA.assertOkStatus();
    MergeInput mergeInput = new MergeInput();
    mergeInput.source = "dev";
    MergePatchSetInput in = new MergePatchSetInput();
    in.merge = mergeInput;
    String subject = "update change by merge ps2";
    in.subject = subject;
    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).isNull();
        assertThat(changeInfo.workInProgress).isNull();
    }
    assertThat(wipStateChangedListener.invoked).isFalse();
    // 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 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.");
    assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.message).contains(subject);
}
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) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 50 with ChangeMessageInfo

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

the class CreateMergePatchSetIT method createMergePatchSetWithOtherAuthor.

@Test
public void createMergePatchSetWithOtherAuthor() throws Exception {
    RevCommit initialHead = projectOperations.project(project).getHead("master");
    createBranch(BranchNameKey.create(project, "dev"));
    // create a change for master
    String changeId = createChange().getChangeId();
    testRepo.reset(initialHead);
    PushOneCommit.Result currentMaster = pushTo("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, "change A", "A.txt", "A content").to("refs/heads/dev");
    changeA.assertOkStatus();
    MergeInput mergeInput = new MergeInput();
    mergeInput.source = "dev";
    MergePatchSetInput in = new MergePatchSetInput();
    in.merge = mergeInput;
    String subject = "update change by merge ps2";
    in.subject = subject;
    in.author = new AccountInput();
    in.author.name = "Other Author";
    in.author.email = "otherauthor@example.com";
    gApi.changes().id(changeId).createMergePatchSet(in);
    // 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 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.");
    CommitInfo commitInfo = changeInfo.revisions.get(changeInfo.currentRevision).commit;
    assertThat(commitInfo.message).contains(subject);
    assertThat(commitInfo.author.name).isEqualTo("Other Author");
    assertThat(commitInfo.author.email).isEqualTo("otherauthor@example.com");
}
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) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) AccountInput(com.google.gerrit.extensions.api.accounts.AccountInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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