Search in sources :

Example 16 with CommentInput

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");
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) Change(com.google.gerrit.entities.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 17 with CommentInput

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");
}
Also used : MailMessage(com.google.gerrit.mail.MailMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) MailMessage(com.google.gerrit.mail.MailMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test)

Example 18 with CommentInput

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");
}
Also used : MailMessage(com.google.gerrit.mail.MailMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) MailMessage(com.google.gerrit.mail.MailMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test)

Example 19 with CommentInput

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;
}
Also used : Comment(com.google.gerrit.extensions.client.Comment) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 20 with CommentInput

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);
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)63 Test (org.junit.Test)48 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)46 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)40 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)32 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)27 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)26 IdString (com.google.gerrit.extensions.restapi.IdString)21 ImmutableList (com.google.common.collect.ImmutableList)14 List (java.util.List)14 Collectors.toList (java.util.stream.Collectors.toList)14 ArrayList (java.util.ArrayList)12 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)11 Change (com.google.gerrit.entities.Change)9 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)8 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)6 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)6 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)5 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 Comment (com.google.gerrit.extensions.client.Comment)4