use of com.google.gerrit.extensions.common.CommentInfo 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.common.CommentInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method publishCommentsOnPushOnlyPublishesDraftsOnUpdatedChanges.
@Test
public void publishCommentsOnPushOnlyPublishesDraftsOnUpdatedChanges() throws Exception {
PushOneCommit.Result r1 = createChange();
PushOneCommit.Result r2 = createChange();
String id1 = r1.getChangeId();
String id2 = r2.getChangeId();
addDraft(id1, r1.getCommit().name(), newDraft(FILE_NAME, 1, "comment1"));
CommentInfo c2 = addDraft(id2, r2.getCommit().name(), newDraft(FILE_NAME, 1, "comment2"));
assertThat(getPublishedComments(id1)).isEmpty();
assertThat(getPublishedComments(id2)).isEmpty();
amendChange(id2, "refs/for/master%publish-comments");
assertThat(getPublishedComments(id1)).isEmpty();
assertThat(gApi.changes().id(id1).drafts()).hasSize(1);
Collection<CommentInfo> cs2 = getPublishedComments(id2);
assertThat(cs2.stream().map(c -> c.message)).containsExactly("comment2");
assertThat(cs2.stream().map(c -> c.id)).containsExactly(c2.id);
assertThat(getLastMessage(id1)).doesNotMatch("[Cc]omment");
assertThat(getLastMessage(id2)).isEqualTo("Patch Set 2:\n\n(1 comment)");
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class RevisionIT method comments.
@Test
public void comments() throws Exception {
PushOneCommit.Result r = createChange();
CommentInput in = new CommentInput();
in.line = 1;
in.message = "nit: trailing whitespace";
in.path = FILE_NAME;
ReviewInput reviewInput = new ReviewInput();
Map<String, List<CommentInput>> comments = new HashMap<>();
comments.put(FILE_NAME, Collections.singletonList(in));
reviewInput.comments = comments;
reviewInput.message = "comment test";
gApi.changes().id(r.getChangeId()).current().review(reviewInput);
Map<String, List<CommentInfo>> out = gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).comments();
assertThat(out).hasSize(1);
CommentInfo comment = Iterables.getOnlyElement(out.get(FILE_NAME));
assertThat(comment.message).isEqualTo(in.message);
assertThat(comment.author.email).isEqualTo(admin.email());
assertThat(comment.path).isNull();
List<CommentInfo> list = gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).commentsAsList();
assertThat(list).hasSize(1);
CommentInfo comment2 = list.get(0);
assertThat(comment2.path).isEqualTo(FILE_NAME);
assertThat(comment2.line).isEqualTo(comment.line);
assertThat(comment2.message).isEqualTo(comment.message);
assertThat(comment2.author.email).isEqualTo(comment.author.email);
assertThat(gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).comment(comment.id).get().message).isEqualTo(in.message);
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf.
@Test
public void voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf() throws Exception {
allowRunAs();
PushOneCommit.Result r = createChange();
requestScopeOperations.setApiUser(user.id());
DraftInput di = new DraftInput();
di.path = Patch.COMMIT_MSG;
di.side = Side.REVISION;
di.line = 1;
di.message = "inline comment";
gApi.changes().id(r.getChangeId()).current().createDraft(di);
requestScopeOperations.setApiUser(admin.id());
// Things that aren't allowed with on_behalf_of:
// - no labels.
// - publish other user's drafts.
ReviewInput in = new ReviewInput();
in.message = "message";
in.drafts = DraftHandling.PUBLISH;
RestResponse res = adminRestSession.postWithHeaders("/changes/" + r.getChangeId() + "/revisions/current/review", in, runAsHeader(user.id()));
res.assertOK();
ChangeMessageInfo m = Iterables.getLast(gApi.changes().id(r.getChangeId()).get().messages);
assertThat(m.message).endsWith(in.message);
assertThat(m.author._accountId).isEqualTo(user.id().get());
CommentInfo c = Iterables.getOnlyElement(gApi.changes().id(r.getChangeId()).commentsRequest().get().get(di.path));
assertThat(c.author._accountId).isEqualTo(user.id().get());
assertThat(c.message).isEqualTo(di.message);
requestScopeOperations.setApiUser(user.id());
assertThat(gApi.changes().id(r.getChangeId()).drafts()).isEmpty();
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class PatchsetOperationsImplTest method zoneOfCreationDateOfDraftCommentCanBeOmitted.
@Test
public void zoneOfCreationDateOfDraftCommentCanBeOmitted() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
// As we don't care about the exact time zone internally used as a default, do a relative test
// so that we don't need to assert on exact instants in time. For a relative test, we need two
// comments whose creation date should be exactly the specified amount apart.
// Don't use nanos or millis. NoteDb supports only second precision.
LocalDateTime creationTime1 = LocalDateTime.of(2020, Month.SEPTEMBER, 15, 12, 10, 43);
LocalDateTime creationTime2 = creationTime1.plusMinutes(10);
String commentUuid1 = changeOperations.change(changeId).currentPatchset().newDraftComment().createdOn(creationTime1).create();
String commentUuid2 = changeOperations.change(changeId).currentPatchset().newDraftComment().createdOn(creationTime2).create();
CommentInfo comment1 = getDraftCommentFromServer(changeId, commentUuid1);
Instant comment1Creation = comment1.updated.toInstant();
CommentInfo comment2 = getDraftCommentFromServer(changeId, commentUuid2);
Instant comment2Creation = comment2.updated.toInstant();
Duration commentCreationDifference = Duration.between(comment1Creation, comment2Creation);
assertThat(commentCreationDifference).isEqualTo(Duration.ofMinutes(10));
}
Aggregations