use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class SubmitWithStickyApprovalDiffIT method postSubmitDiffCannotBeTooBigWithLargeComments.
@Test
@GerritConfig(name = "change.cumulativeCommentSizeLimit", value = "10k")
public void postSubmitDiffCannotBeTooBigWithLargeComments() throws Exception {
Change.Id changeId = changeOperations.newChange().project(project).file("file").content("content").create();
gApi.changes().id(changeId.get()).current().review(ReviewInput.approve());
// unrelated comment taking up most of the space, making post submit diff shorter.
String message = new String(new char[9700]).replace("\0", "a");
ReviewInput reviewInput = new ReviewInput().message(message);
CommentInput commentInput = new CommentInput();
commentInput.line = 1;
commentInput.path = "file";
reviewInput.comments = ImmutableMap.of("file", ImmutableList.of(commentInput));
gApi.changes().id(changeId.get()).current().review(reviewInput);
String content = new String(new char[500]).replace("\0", "a");
changeOperations.change(changeId).newPatchset().file("file").content(content).create();
// Post submit diff is over the cumulativeCommentSizeLimit, since the comment took most of
// the space (even though the post submit diff is not limited).
gApi.changes().id(changeId.get()).current().submit();
assertThat(Iterables.getLast(gApi.changes().id(changeId.get()).messages()).message).isEqualTo("Change has been successfully merged\n\n1 is the latest approved patch-set.\nThe " + "change was submitted with unreviewed changes in the following " + "files:\n\n```\nThe name of the file: file\nInsertions: 1, Deletions: 1.\n\nThe" + " diff is too large to show. Please review the diff.\n```\n");
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class MailProcessorIT method limitNumberOfComments.
@Test
@GerritConfig(name = "change.maxComments", value = "9")
public void limitNumberOfComments() throws Exception {
// This change has 2 change messages and 2 comments.
String changeId = createChangeWithReview();
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
CommentInput commentInput = new CommentInput();
commentInput.line = 1;
commentInput.message = "foo";
commentInput.path = FILE_NAME;
RobotCommentInput robotCommentInput = TestCommentHelper.createRobotCommentInputWithMandatoryFields(FILE_NAME);
ReviewInput reviewInput = new ReviewInput();
reviewInput.comments = ImmutableMap.of(FILE_NAME, ImmutableList.of(commentInput));
reviewInput.robotComments = ImmutableMap.of(FILE_NAME, ImmutableList.of(robotCommentInput));
// Add 1 change message and another 2 comments. Total count is now 7, which is still OK.
gApi.changes().id(changeId).current().review(reviewInput);
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
MailMessage.Builder mailMessage = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", "1) change message", "2) reply to comment", "3) file comment");
mailMessage.textContent(txt + textFooterForChange(changeInfo._number, ts));
ImmutableSet<CommentInfo> commentsBefore = getCommentsAndRobotComments(changeId);
// Should have 4 comments (and 3 change messages).
assertThat(commentsBefore).hasSize(4);
// The email adds 3 new comments (of which 1 is the change message).
mailProcessor.process(mailMessage.build());
ImmutableSet<CommentInfo> commentsAfter = getCommentsAndRobotComments(changeId);
assertThat(commentsAfter).isEqualTo(commentsBefore);
assertNotifyTo(user);
Message message = sender.nextMessage();
assertThat(message.body()).contains("rejected one or more comments");
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput 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.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentContextIT method createChangeWithComment.
private String createChangeWithComment(int startLine, int endLine) throws Exception {
PushOneCommit.Result result = createChange(testRepo, "master", SUBJECT, FILE_NAME, FILE_CONTENT, "topic");
String changeId = result.getChangeId();
String ps1 = result.getCommit().name();
Comment.Range commentRange = createCommentRange(startLine, endLine);
CommentInput comment = CommentsUtil.newComment(FILE_NAME, Side.REVISION, commentRange, "comment", false);
CommentsUtil.addComments(gApi, changeId, ps1, comment);
return changeId;
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentContextIT method commentContextReturnsCorrectContentTypeForCommitMessage.
@Test
public void commentContextReturnsCorrectContentTypeForCommitMessage() throws Exception {
PushOneCommit.Result result = createChange(testRepo, "master", SUBJECT, FILE_NAME, FILE_CONTENT, "topic");
String changeId = result.getChangeId();
String ps1 = result.getCommit().name();
CommentInput comment = CommentsUtil.newComment(COMMIT_MSG, Side.REVISION, 7, "comment", false);
CommentsUtil.addComments(gApi, changeId, ps1, comment);
List<CommentInfo> comments = gApi.changes().id(changeId).commentsRequest().withContext(true).getAsList();
assertThat(comments).hasSize(1);
assertThat(comments.get(0).path).isEqualTo(COMMIT_MSG);
assertThat(comments.get(0).sourceContentType).isEqualTo(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE);
}
Aggregations