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();
}
}
}
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);
}
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());
}
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);
}
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());
}
Aggregations