use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES in project gerrit by GerritCodeReview.
the class AbstractPushForReview method publishCommentsOnPushPublishesDraftsOnAllRevisions.
@Test
public void publishCommentsOnPushPublishesDraftsOnAllRevisions() throws Exception {
PushOneCommit.Result r = createChange();
String rev1 = r.getCommit().name();
CommentInfo c1 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment1"));
CommentInfo c2 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment2"));
r = amendChange(r.getChangeId());
String rev2 = r.getCommit().name();
CommentInfo c3 = addDraft(r.getChangeId(), rev2, newDraft(FILE_NAME, 1, "comment3"));
assertThat(getPublishedComments(r.getChangeId())).isEmpty();
gApi.changes().id(r.getChangeId()).addReviewer(user.email());
sender.clear();
amendChange(r.getChangeId(), "refs/for/master%publish-comments");
Collection<CommentInfo> comments = getPublishedComments(r.getChangeId());
assertThat(comments.stream().map(c -> c.id)).containsExactly(c1.id, c2.id, c3.id);
assertThat(comments.stream().map(c -> c.message)).containsExactly("comment1", "comment2", "comment3");
/* Assert the correctness of the API messages */
List<ChangeMessageInfo> allMessages = getMessages(r.getChangeId());
List<String> messagesText = allMessages.stream().map(m -> m.message).collect(toList());
assertThat(messagesText).containsExactly("Uploaded patch set 1.", "Uploaded patch set 2.", "Uploaded patch set 3.", "Patch Set 3:\n\n(3 comments)").inOrder();
/* Assert the tags - PS#2 comments do not have tags, PS#3 upload is autogenerated */
List<String> messagesTags = allMessages.stream().map(m -> m.tag).collect(toList());
assertThat(messagesTags.get(2)).isEqualTo("autogenerated:gerrit:newPatchSet");
assertThat(messagesTags.get(3)).isNull();
/* Assert the correctness of the emails sent */
List<String> emailMessages = sender.getMessages().stream().map(Message::body).sorted(Comparator.comparingInt(m -> m.contains("reexamine") ? 0 : 1)).collect(toList());
assertThat(emailMessages).hasSize(2);
assertThat(emailMessages.get(0)).contains("Gerrit-MessageType: newpatchset");
assertThat(emailMessages.get(0)).contains("I'd like you to reexamine a change");
assertThat(emailMessages.get(0)).doesNotContain("Uploaded patch set 3");
assertThat(emailMessages.get(1)).contains("Gerrit-MessageType: comment");
assertThat(emailMessages.get(1)).contains("Patch Set 3:\n\n(3 comments)");
assertThat(emailMessages.get(1)).contains("PS1, Line 1:");
assertThat(emailMessages.get(1)).contains("PS2, Line 1:");
/* Assert the correctness of the NoteDb change meta commits */
List<RevCommit> commitMessages = getChangeMetaCommitsInReverseOrder(r.getChange().getId());
assertThat(commitMessages).hasSize(5);
assertThat(commitMessages.get(0).getShortMessage()).isEqualTo("Create change");
assertThat(commitMessages.get(1).getShortMessage()).isEqualTo("Create patch set 2");
assertThat(commitMessages.get(2).getShortMessage()).isEqualTo("Update patch set 2");
assertThat(commitMessages.get(3).getShortMessage()).isEqualTo("Create patch set 3");
assertThat(commitMessages.get(4).getFullMessage()).isEqualTo("Update patch set 3\n" + "\n" + "Patch Set 3:\n" + "\n" + "(3 comments)\n" + "\n" + "Patch-set: 3\n");
}
use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES in project gerrit by GerritCodeReview.
the class ChangeEditIT method assertChangeMessages.
private void assertChangeMessages(String changeId, List<String> expectedMessages) throws Exception {
ChangeInfo ci = get(changeId, MESSAGES);
assertThat(ci.messages).isNotNull();
assertThat(ci.messages).hasSize(expectedMessages.size());
List<String> actualMessages = ci.messages.stream().map(message -> message.message).collect(toList());
assertThat(actualMessages).containsExactlyElementsIn(expectedMessages).inOrder();
}
use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES in project gerrit by GerritCodeReview.
the class RobotCommentsIT method addedRobotCommentsAreLinkedToChangeMessages.
@UseClockStep
@Test
public void addedRobotCommentsAreLinkedToChangeMessages() throws Exception {
// Advancing the time after creating the change so that the first robot comment is not in the
// same timestamp as with the change creation.
TestTimeUtil.incrementClock(10, TimeUnit.SECONDS);
RobotCommentInput c1 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
RobotCommentInput c2 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
RobotCommentInput c3 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
// Give the robot comments identifiable names for testing
c1.message = "robot comment 1";
c2.message = "robot comment 2";
c3.message = "robot comment 3";
testCommentHelper.addRobotComment(changeId, c1, "robot message 1");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
testCommentHelper.addRobotComment(changeId, c2, "robot message 2");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
testCommentHelper.addRobotComment(changeId, c3, "robot message 3");
TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
Map<String, List<RobotCommentInfo>> robotComments = gApi.changes().id(changeId).robotComments();
List<RobotCommentInfo> robotCommentsList = robotComments.values().stream().flatMap(List::stream).collect(toList());
List<ChangeMessageInfo> allMessages = gApi.changes().id(changeId).get(MESSAGES).messages.stream().collect(toList());
assertThat(allMessages.stream().map(cm -> cm.message).collect(toList())).containsExactly("Uploaded patch set 1.", "Patch Set 1:\n\n(1 comment)\n\nrobot message 1", "Patch Set 1:\n\n(1 comment)\n\nrobot message 2", "Patch Set 1:\n\n(1 comment)\n\nrobot message 3");
assertThat(robotCommentsList.stream().map(c -> c.message).collect(toList())).containsExactly("robot comment 1", "robot comment 2", "robot comment 3");
String message1ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 1")).collect(onlyElement()).id;
String message2ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 2")).collect(onlyElement()).id;
String message3ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 3")).collect(onlyElement()).id;
String comment1MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 1")).collect(onlyElement()).changeMessageId;
String comment2MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 2")).collect(onlyElement()).changeMessageId;
String comment3MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 3")).collect(onlyElement()).changeMessageId;
/**
* All change messages have the auto-generated tag. Robot comments can be linked to
* auto-generated messages where each comment is linked to the next nearest change message in
* timestamp
*/
assertThat(message1ChangeId).isEqualTo(comment1MessageId);
assertThat(message2ChangeId).isEqualTo(comment2MessageId);
assertThat(message3ChangeId).isEqualTo(comment3MessageId);
}
use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES in project gerrit by GerritCodeReview.
the class ChangeMessagesIT method deleteOneChangeMessage.
private void deleteOneChangeMessage(int changeNum, int deletedMessageIndex, TestAccount deletedBy, String reason) throws Exception {
List<ChangeMessageInfo> messagesBeforeDeletion = gApi.changes().id(changeNum).messages();
List<CommentInfo> commentsBefore = getChangeSortedComments(changeNum);
List<RevCommit> commitsBefore = getChangeMetaCommitsInReverseOrder(Change.id(changeNum));
String id = messagesBeforeDeletion.get(deletedMessageIndex).id;
DeleteChangeMessageInput input = new DeleteChangeMessageInput(reason);
ChangeMessageInfo info = gApi.changes().id(changeNum).message(id).delete(input);
// Verify the return change message info is as expect.
String expectedMessage = "Change message removed by: " + deletedBy.getNameEmail();
if (!Strings.isNullOrEmpty(reason)) {
expectedMessage = expectedMessage + "\nReason: " + reason;
}
assertThat(info.message).isEqualTo(expectedMessage);
List<ChangeMessageInfo> messagesAfterDeletion = gApi.changes().id(changeNum).messages();
assertMessagesAfterDeletion(messagesBeforeDeletion, messagesAfterDeletion, deletedMessageIndex, expectedMessage);
assertCommentsAfterDeletion(changeNum, commentsBefore);
// Verify change index is updated after deletion.
List<ChangeInfo> changes = gApi.changes().query("message removed").get();
assertThat(changes.stream().map(c -> c._number).collect(toSet())).contains(changeNum);
// Verifies states of commits.
assertMetaCommitsAfterDeletion(commitsBefore, changeNum, id, deletedBy, reason);
}
use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES in project gerrit by GerritCodeReview.
the class NoteDbOnlyIT method retryOnLockFailureWithAtomicUpdates.
@Test
public void retryOnLockFailureWithAtomicUpdates() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getChange().getId();
String master = "refs/heads/master";
ObjectId initial;
try (Repository repo = repoManager.openRepository(project)) {
ensureAtomicTransactions(repo);
initial = repo.exactRef(master).getObjectId();
}
AtomicInteger updateRepoCalledCount = new AtomicInteger();
AtomicInteger updateChangeCalledCount = new AtomicInteger();
AtomicInteger afterUpdateReposCalledCount = new AtomicInteger();
String result = retryHelper.changeUpdate("testUpdateRefAndAddMessageOp", batchUpdateFactory -> {
try (BatchUpdate bu = newBatchUpdate(batchUpdateFactory)) {
bu.addOp(id, new UpdateRefAndAddMessageOp(updateRepoCalledCount, updateChangeCalledCount));
bu.execute(new ConcurrentWritingListener(afterUpdateReposCalledCount));
}
return "Done";
}).call();
assertThat(result).isEqualTo("Done");
assertThat(updateRepoCalledCount.get()).isEqualTo(2);
assertThat(afterUpdateReposCalledCount.get()).isEqualTo(2);
assertThat(updateChangeCalledCount.get()).isEqualTo(2);
List<String> messages = getMessages(id);
assertThat(Iterables.getLast(messages)).isEqualTo(UpdateRefAndAddMessageOp.CHANGE_MESSAGE);
assertThat(Collections.frequency(messages, UpdateRefAndAddMessageOp.CHANGE_MESSAGE)).isEqualTo(1);
try (Repository repo = repoManager.openRepository(project)) {
// Op lost the race, so the other writer's commit happened first. Then op retried and wrote
// its commit with the other writer's commit as parent.
assertThat(commitMessages(repo, initial, repo.exactRef(master).getObjectId())).containsExactly(ConcurrentWritingListener.MSG_PREFIX + "1", UpdateRefAndAddMessageOp.COMMIT_MESSAGE).inOrder();
}
}
Aggregations