use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class MailProcessorIT method limitCumulativeCommentSize.
@Test
@GerritConfig(name = "change.cumulativeCommentSizeLimit", value = "7k")
public void limitCumulativeCommentSize() throws Exception {
// Use large sizes because autogenerated messages already have O(100) bytes.
String commentText2000Bytes = new String(new char[2000]).replace("\0", "x");
String changeId = createChangeWithReview();
CommentInput commentInput = new CommentInput();
commentInput.line = 1;
commentInput.message = commentText2000Bytes;
commentInput.path = FILE_NAME;
ReviewInput reviewInput = new ReviewInput().message(commentText2000Bytes);
reviewInput.comments = ImmutableMap.of(FILE_NAME, ImmutableList.of(commentInput));
// Use up ~4000 bytes.
gApi.changes().id(changeId).current().review(reviewInput);
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
// Hit the limit when trying that again.
MailMessage.Builder mailMessage = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", "change message: " + commentText2000Bytes, "reply to comment: " + commentText2000Bytes, null);
mailMessage.textContent(txt + textFooterForChange(changeInfo._number, ts));
List<CommentInfo> commentsBefore = testCommentHelper.getPublishedComments(changeId);
mailProcessor.process(mailMessage.build());
assertThat(testCommentHelper.getPublishedComments(changeId)).isEqualTo(commentsBefore);
assertNotifyTo(user);
Message message = sender.nextMessage();
assertThat(message.body()).contains("rejected one or more comments");
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class MailProcessorIT method parseAndPersistPatchsetLevelComment.
@Test
public void parseAndPersistPatchsetLevelComment() throws Exception {
String changeId = createChangeWithReview();
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
// Build Message
MailMessage.Builder b = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", "Test Message", null, null);
b.textContent(txt + textFooterForChange(changeInfo._number, 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\n(1 comment)");
assertThat(Iterables.getLast(messages).tag).isEqualTo("mailMessageId=some id");
// Assert comment
List<CommentInfo> comments = gApi.changes().id(changeId).current().commentsAsList();
assertThat(comments).hasSize(3);
assertThat(comments.get(0).path).isEqualTo(PATCHSET_LEVEL);
assertThat(comments.get(0).message).isEqualTo("Test Message");
assertThat(comments.get(0).tag).isEqualTo("mailMessageId=some id");
assertThat(comments.get(0).parent).isNull();
assertThat(comments.get(0).side).isNull();
assertThat(comments.get(0).line).isNull();
assertThat(comments.get(0).parent).isNull();
assertThat(comments.get(0).inReplyTo).isNull();
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class MailProcessorIT method validateChangeMessage_rejected.
@Test
public void validateChangeMessage_rejected() throws Exception {
String changeId = createChangeWithReview();
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
setupFailValidation(CommentForValidation.CommentType.CHANGE_MESSAGE, changeInfo.project, changeInfo._number);
MailMessage.Builder b = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", COMMENT_TEXT, null, null);
b.textContent(txt + textFooterForChange(changeInfo._number, ts));
List<CommentInfo> commentsBefore = testCommentHelper.getPublishedComments(changeId);
mailProcessor.process(b.build());
assertThat(testCommentHelper.getPublishedComments(changeId)).isEqualTo(commentsBefore);
assertNotifyTo(user);
Message message = sender.nextMessage();
assertThat(message.body()).contains("rejected one or more comments");
// ensure the message header contains a valid message id.
assertThat(((StringEmailHeader) message.headers().get("Message-ID")).getString()).containsMatch("<someid-REJECTION-HTML@" + new URL(canonicalWebUrl.get()).getHost() + ">");
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class ChangesRestApiBindingsIT method commentEndpoints.
@Test
public void commentEndpoints() throws Exception {
String changeId = createChange().getChangeId();
for (RestCall restCall : COMMENT_ENDPOINTS) {
DraftInput draftInput = new DraftInput();
draftInput.path = Patch.COMMIT_MSG;
draftInput.side = Side.REVISION;
draftInput.line = 1;
draftInput.message = "draft comment";
CommentInfo commentInfo = gApi.changes().id(changeId).current().createDraft(draftInput).get();
ReviewInput reviewInput = new ReviewInput();
reviewInput.drafts = DraftHandling.PUBLISH;
gApi.changes().id(changeId).current().review(reviewInput);
RestApiCallHelper.execute(adminRestSession, restCall, changeId, "current", commentInfo.id);
}
}
use of com.google.gerrit.extensions.common.CommentInfo 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);
}
Aggregations