Search in sources :

Example 1 with ChangeMessage

use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.

the class CommentsUtil method linkCommentsToChangeMessages.

/**
 * This method populates the "changeMessageId" field of the comments parameter based on timestamp
 * matching. The comments objects will be modified.
 *
 * <p>Each comment will be matched to the nearest next change message in timestamp
 *
 * @param comments the list of comments
 * @param changeMessages list of change messages
 */
public static void linkCommentsToChangeMessages(List<? extends CommentInfo> comments, List<ChangeMessage> changeMessages, boolean skipAutoGeneratedMessages) {
    ArrayList<ChangeMessage> sortedChangeMessages = changeMessages.stream().sorted(comparing(ChangeMessage::getWrittenOn)).collect(toCollection(ArrayList::new));
    ArrayList<CommentInfo> sortedCommentInfos = comments.stream().sorted(comparing(c -> c.updated)).collect(toCollection(ArrayList::new));
    int cmItr = 0;
    for (CommentInfo comment : sortedCommentInfos) {
        // message in timestamp
        while (cmItr < sortedChangeMessages.size()) {
            ChangeMessage cm = sortedChangeMessages.get(cmItr);
            if (isAfter(comment, cm) || (skipAutoGeneratedMessages && isAutoGenerated(cm))) {
                cmItr += 1;
            } else {
                break;
            }
        }
        if (cmItr < changeMessages.size()) {
            comment.changeMessageId = sortedChangeMessages.get(cmItr).getKey().uuid();
        }
    }
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) CommentInfo(com.google.gerrit.extensions.common.CommentInfo)

Example 2 with ChangeMessage

use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.

the class ChangeJson method messages.

private ImmutableList<ChangeMessageInfo> messages(ChangeData cd) {
    List<ChangeMessage> messages = cmUtil.byChange(cd.notes());
    if (messages.isEmpty()) {
        return ImmutableList.of();
    }
    List<ChangeMessageInfo> result = Lists.newArrayListWithCapacity(messages.size());
    for (ChangeMessage message : messages) {
        result.add(createChangeMessageInfo(message, accountLoader));
    }
    return ImmutableList.copyOf(result);
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) ChangeMessagesUtil.createChangeMessageInfo(com.google.gerrit.server.ChangeMessagesUtil.createChangeMessageInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo)

Example 3 with ChangeMessage

use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.

the class ChangeNotesTest method changeMessageOnePatchSet.

@Test
public void changeMessageOnePatchSet() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
    update.setChangeMessage("Just a little code change.\n");
    update.commit();
    ChangeNotes notes = newNotes(c);
    ChangeMessage cm = Iterables.getOnlyElement(notes.getChangeMessages());
    assertThat(cm.getMessage()).isEqualTo("Just a little code change.\n");
    assertThat(cm.getAuthor()).isEqualTo(changeOwner.getAccount().id());
    assertThat(cm.getPatchSetId()).isEqualTo(c.currentPatchSetId());
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 4 with ChangeMessage

use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.

the class ChangeNotesTest method changeMessagesMultiplePatchSets.

@Test
public void changeMessagesMultiplePatchSets() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putReviewer(changeOwner.getAccount().id(), REVIEWER);
    update.setChangeMessage("This is the change message for the first PS.");
    update.commit();
    PatchSet.Id ps1 = c.currentPatchSetId();
    incrementPatchSet(c);
    update = newUpdate(c, changeOwner);
    update.setChangeMessage("This is the change message for the second PS.");
    update.commit();
    PatchSet.Id ps2 = c.currentPatchSetId();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getChangeMessages()).hasSize(2);
    ChangeMessage cm1 = notes.getChangeMessages().get(0);
    assertThat(cm1.getPatchSetId()).isEqualTo(ps1);
    assertThat(cm1.getMessage()).isEqualTo("This is the change message for the first PS.");
    assertThat(cm1.getAuthor()).isEqualTo(changeOwner.getAccount().id());
    ChangeMessage cm2 = notes.getChangeMessages().get(1);
    assertThat(cm2.getPatchSetId()).isEqualTo(ps2);
    assertThat(cm2.getMessage()).isEqualTo("This is the change message for the second PS.");
    assertThat(cm2.getAuthor()).isEqualTo(changeOwner.getAccount().id());
    assertThat(cm2.getPatchSetId()).isEqualTo(ps2);
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 5 with ChangeMessage

use of com.google.gerrit.entities.ChangeMessage in project gerrit by GerritCodeReview.

the class ChangeNotesTest method changeMessageWithMultipleParagraphs.

@Test
public void changeMessageWithMultipleParagraphs() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setChangeMessage("Testing paragraph 1\n\nTesting paragraph 2\n\nTesting paragraph 3");
    update.commit();
    ChangeNotes notes = newNotes(c);
    ChangeMessage cm1 = Iterables.getOnlyElement(notes.getChangeMessages());
    assertThat(cm1.getMessage()).isEqualTo("Testing paragraph 1\n" + "\n" + "Testing paragraph 2\n" + "\n" + "Testing paragraph 3");
    assertThat(cm1.getAuthor()).isEqualTo(changeOwner.getAccount().id());
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Aggregations

ChangeMessage (com.google.gerrit.entities.ChangeMessage)31 Test (org.junit.Test)23 Change (com.google.gerrit.entities.Change)13 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)6 List (java.util.List)5 Account (com.google.gerrit.entities.Account)4 LabelId (com.google.gerrit.entities.LabelId)4 Entities (com.google.gerrit.proto.Entities)4 CurrentUser (com.google.gerrit.server.CurrentUser)4 Inject (com.google.inject.Inject)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)3 Operation (com.google.gerrit.entities.AttentionSetUpdate.Operation)3 CODE_REVIEW (com.google.gerrit.entities.LabelId.CODE_REVIEW)3 VERIFIED (com.google.gerrit.entities.LabelId.VERIFIED)3 RefNames (com.google.gerrit.entities.RefNames)3 SubmitRecord (com.google.gerrit.entities.SubmitRecord)3