Search in sources :

Example 31 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class CommentsIT method addComment.

private void addComment(PushOneCommit.Result r, String message, boolean omitDuplicateComments, Boolean unresolved, String inReplyTo) throws Exception {
    CommentInput c = new CommentInput();
    c.line = 1;
    c.message = message;
    c.path = FILE_NAME;
    c.unresolved = unresolved;
    c.inReplyTo = inReplyTo;
    ReviewInput in = newInput(c);
    in.omitDuplicateComments = omitDuplicateComments;
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(in);
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput)

Example 32 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class NoteDbPrimaryIT method rebuildReviewDb.

@Test
public void rebuildReviewDb() throws Exception {
    Change c = createChange().getChange().change();
    Change.Id id = c.getId();
    CommentInput cin = new CommentInput();
    cin.line = 1;
    cin.message = "Published comment";
    ReviewInput rin = ReviewInput.approve();
    rin.comments = ImmutableMap.of(PushOneCommit.FILE_NAME, ImmutableList.of(cin));
    gApi.changes().id(id.get()).current().review(ReviewInput.approve());
    DraftInput din = new DraftInput();
    din.path = PushOneCommit.FILE_NAME;
    din.line = 1;
    din.message = "Draft comment";
    gApi.changes().id(id.get()).current().createDraft(din);
    gApi.changes().id(id.get()).current().review(ReviewInput.approve());
    gApi.changes().id(id.get()).current().createDraft(din);
    assertThat(db.changeMessages().byChange(id)).isNotEmpty();
    assertThat(db.patchSets().byChange(id)).isNotEmpty();
    assertThat(db.patchSetApprovals().byChange(id)).isNotEmpty();
    assertThat(db.patchComments().byChange(id)).isNotEmpty();
    ChangeBundle noteDbBundle = ChangeBundle.fromNotes(commentsUtil, notesFactory.create(db, project, id));
    setNoteDbPrimary(id);
    db.changeMessages().delete(db.changeMessages().byChange(id));
    db.patchSets().delete(db.patchSets().byChange(id));
    db.patchSetApprovals().delete(db.patchSetApprovals().byChange(id));
    db.patchComments().delete(db.patchComments().byChange(id));
    ChangeMessage bogusMessage = ChangeMessagesUtil.newMessage(c.currentPatchSetId(), identifiedUserFactory.create(admin.getId()), TimeUtil.nowTs(), "some message", null);
    db.changeMessages().insert(Collections.singleton(bogusMessage));
    rebuilderWrapper.rebuildReviewDb(db, project, id);
    assertThat(db.changeMessages().byChange(id)).isNotEmpty();
    assertThat(db.patchSets().byChange(id)).isNotEmpty();
    assertThat(db.patchSetApprovals().byChange(id)).isNotEmpty();
    assertThat(db.patchComments().byChange(id)).isNotEmpty();
    ChangeBundle reviewDbBundle = bundleReader.fromReviewDb(ReviewDbUtil.unwrapDb(db), id);
    assertThat(reviewDbBundle.differencesFrom(noteDbBundle)).isEmpty();
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeBundle(com.google.gerrit.server.notedb.ChangeBundle) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 33 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method putComment.

private void putComment(TestAccount account, Change.Id id, int line, String msg, String inReplyTo) throws Exception {
    CommentInput in = new CommentInput();
    in.line = line;
    in.message = msg;
    in.inReplyTo = inReplyTo;
    ReviewInput rin = new ReviewInput();
    rin.comments = new HashMap<>();
    rin.comments.put(PushOneCommit.FILE_NAME, ImmutableList.of(in));
    rin.drafts = ReviewInput.DraftHandling.KEEP;
    AcceptanceTestRequestScope.Context old = setApiUser(account);
    try {
        gApi.changes().id(id.get()).current().review(rin);
    } finally {
        atrScope.set(old);
    }
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput)

Example 34 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class PostReviewIT method validateCommentsInInput_commentOK.

@Test
public void validateCommentsInInput_commentOK() throws Exception {
    PushOneCommit.Result r = createChange();
    when(mockCommentValidator.validateComments(captorCtx.capture(), captor.capture())).thenReturn(ImmutableList.of());
    ReviewInput input = new ReviewInput().message(COMMENT_TEXT);
    CommentInput comment = newComment(r.getChange().currentFilePaths().get(0));
    comment.updated = new Timestamp(0);
    input.comments = ImmutableMap.of(comment.path, ImmutableList.of(comment));
    assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).isEmpty();
    gApi.changes().id(r.getChangeId()).current().review(input);
    assertValidatorCalledWith(CHANGE_MESSAGE_FOR_VALIDATION, FILE_COMMENT_FOR_VALIDATION);
    assertThat(testCommentHelper.getPublishedComments(r.getChangeId())).hasSize(1);
    assertThat(captorCtx.getAllValues()).containsExactly(contextFor(r));
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 35 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class PostReviewIT method validateCumulativeCommentSize.

@Test
@GerritConfig(name = "change.cumulativeCommentSizeLimit", value = "7k")
public void validateCumulativeCommentSize() throws Exception {
    PushOneCommit.Result r = createChange();
    when(mockCommentValidator.validateComments(eq(contextFor(r)), any())).thenReturn(ImmutableList.of());
    // Use large sizes because autogenerated messages already have O(100) bytes.
    String commentText2000Bytes = new String(new char[2000]).replace("\0", "x");
    String filePath = r.getChange().currentFilePaths().get(0);
    ReviewInput reviewInput = new ReviewInput().message(commentText2000Bytes);
    CommentInput commentInput = new CommentInput();
    commentInput.line = 1;
    commentInput.message = commentText2000Bytes;
    commentInput.path = filePath;
    reviewInput.comments = ImmutableMap.of(filePath, ImmutableList.of(commentInput));
    // Use up ~4000 bytes.
    gApi.changes().id(r.getChangeId()).current().review(reviewInput);
    // Hit the limit when trying that again.
    BadRequestException exception = assertThrows(BadRequestException.class, () -> gApi.changes().id(r.getChangeId()).current().review(reviewInput));
    assertThat(exception).hasMessageThat().contains("Exceeding maximum cumulative size of comments");
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

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