Search in sources :

Example 1 with ChangeMessageInfo

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

the class CreateChangeIT method cherryPickCommitWithoutChangeId.

@Test
public void cherryPickCommitWithoutChangeId() throws Exception {
    // This test is a little superfluous, since the current cherry-pick code ignores
    // the commit message of the to-be-cherry-picked change, using the one in
    // CherryPickInput instead.
    CherryPickInput input = new CherryPickInput();
    input.destination = "foo";
    input.message = "it goes to foo branch";
    gApi.projects().name(project.get()).branch(input.destination).create(new BranchInput());
    RevCommit revCommit = createNewCommitWithoutChangeId();
    ChangeInfo changeInfo = gApi.projects().name(project.get()).commit(revCommit.getName()).cherryPick(input).get();
    assertThat(changeInfo.messages).hasSize(1);
    Iterator<ChangeMessageInfo> messageIterator = changeInfo.messages.iterator();
    String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", revCommit.getName());
    assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
    RevisionInfo revInfo = changeInfo.revisions.get(changeInfo.currentRevision);
    assertThat(revInfo).isNotNull();
    CommitInfo commitInfo = revInfo.commit;
    assertThat(commitInfo.message).isEqualTo(input.message + "\n\nChange-Id: " + changeInfo.changeId + "\n");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with ChangeMessageInfo

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

the class CreateChangeIT method cherryPickCommitWithChangeId.

@Test
public void cherryPickCommitWithChangeId() throws Exception {
    CherryPickInput input = new CherryPickInput();
    input.destination = "foo";
    RevCommit revCommit = createChange().getCommit();
    List<String> footers = revCommit.getFooterLines("Change-Id");
    assertThat(footers).hasSize(1);
    String changeId = footers.get(0);
    input.message = "it goes to foo branch\n\nChange-Id: " + changeId;
    gApi.projects().name(project.get()).branch(input.destination).create(new BranchInput());
    ChangeInfo changeInfo = gApi.projects().name(project.get()).commit(revCommit.getName()).cherryPick(input).get();
    assertThat(changeInfo.messages).hasSize(1);
    Iterator<ChangeMessageInfo> messageIterator = changeInfo.messages.iterator();
    String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", revCommit.getName());
    assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
    RevisionInfo revInfo = changeInfo.revisions.get(changeInfo.currentRevision);
    assertThat(revInfo).isNotNull();
    assertThat(revInfo.commit.message).isEqualTo(input.message + "\n");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with ChangeMessageInfo

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

the class ListMailFilterIT method listFilterBlacklistFiltersListedUser.

@Test
@GerritConfig(name = "receiveemail.filter.mode", value = "BLACKLIST")
@GerritConfig(name = "receiveemail.filter.patterns", values = { ".+@example\\.com", "a@b\\.com" })
public void listFilterBlacklistFiltersListedUser() 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(2);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Test(org.junit.Test)

Example 4 with ChangeMessageInfo

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

the class MailProcessorIT method parseAndPersistChangeMessage.

@Test
public void parseAndPersistChangeMessage() throws Exception {
    String changeId = createChangeWithReview();
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    List<CommentInfo> comments = gApi.changes().id(changeId).current().commentsAsList();
    String ts = MailUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(comments.get(0).updated.toInstant(), ZoneId.of("UTC")));
    // Build Message
    MailMessage.Builder b = messageBuilderWithDefaultFields();
    String txt = newPlaintextBody(canonicalWebUrl.get() + "#/c/" + changeInfo._number + "/1", "Test Message", null, null, null);
    b.textContent(txt + textFooterForChange(changeId, ts));
    mailProcessor.process(b.build());
    Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages;
    assertThat(messages).hasSize(3);
    assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n\nTest Message");
    assertThat(Iterables.getLast(messages).tag).isEqualTo("mailMessageId=some id");
}
Also used : MailMessage(com.google.gerrit.server.mail.receive.MailMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test)

Example 5 with ChangeMessageInfo

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

the class ChangeMessagesUtil method createChangeMessageInfoWithReplacedTemplates.

/**
 * {@link ChangeMessage} is served in template form to {@link
 * com.google.gerrit.extensions.api.changes.ChangeApi}. Serve message with replaced templates to
 * the legacy {@link com.google.gerrit.extensions.api.changes.ChangeMessageApi} endpoints.
 * TODO(mariasavtchouk): remove this, after {@link
 * com.google.gerrit.extensions.api.changes.ChangeMessageApi} is deprecated (gate with
 * experiment).
 */
public ChangeMessageInfo createChangeMessageInfoWithReplacedTemplates(ChangeMessage message, AccountLoader accountLoader) {
    ChangeMessageInfo changeMessageInfo = createChangeMessageInfo(message, accountLoader);
    changeMessageInfo.message = accountTemplateUtil.replaceTemplates(message.getMessage());
    return changeMessageInfo;
}
Also used : ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo)

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