Search in sources :

Example 21 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class CommentsIT method deleteDraft.

@Test
public void deleteDraft() throws Exception {
    for (Integer line : lines) {
        PushOneCommit.Result r = createChange();
        Timestamp origLastUpdated = r.getChange().change().getLastUpdatedOn();
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        DraftInput draft = newDraft("file1", Side.REVISION, line, "comment 1");
        CommentInfo returned = addDraft(changeId, revId, draft);
        deleteDraft(changeId, revId, returned.id);
        Map<String, List<CommentInfo>> drafts = getDraftComments(changeId, revId);
        assertThat(drafts).isEmpty();
        // Deleting a draft comment doesn't cause lastUpdatedOn to change.
        assertThat(r.getChange().change().getLastUpdatedOn()).isEqualTo(origLastUpdated);
    }
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 22 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class CommentsIT method postComment.

@Test
public void postComment() throws Exception {
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "first subject", file, contents);
        PushOneCommit.Result r = push.to("refs/for/master");
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", false);
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        revision(r).review(input);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        assertThat(result).isNotEmpty();
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        assertThat(comment).isEqualTo(infoToInput(file).apply(actual));
        assertThat(comment).isEqualTo(infoToInput(file).apply(getPublishedComment(changeId, revId, actual.id)));
    }
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 23 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class CommentsIT method deleteCommentByRewritingCommitHistory.

@Test
public void deleteCommentByRewritingCommitHistory() throws Exception {
    // Creates the following commit history on the meta branch of the test change. Then tries to
    // delete the comments one by one, which will rewrite most of the commits on the 'meta' branch.
    // Commits will be rewritten N times for N added comments. After each deletion, the meta branch
    // should keep its previous state except that the target comment's message should be updated.
    // 1st commit: Create PS1.
    PushOneCommit.Result result1 = createChange(SUBJECT, "a.txt", "a");
    Change.Id id = result1.getChange().getId();
    String changeId = result1.getChangeId();
    String ps1 = result1.getCommit().name();
    // 2nd commit: Add (c1) to PS1.
    CommentInput c1 = newComment("a.txt", "comment 1");
    addComments(changeId, ps1, c1);
    // 3rd commit: Add (c2, c3) to PS1.
    CommentInput c2 = newComment("a.txt", "comment 2");
    CommentInput c3 = newComment("a.txt", "comment 3");
    addComments(changeId, ps1, c2, c3);
    // 4th commit: Add (c4) to PS1.
    CommentInput c4 = newComment("a.txt", "comment 4");
    addComments(changeId, ps1, c4);
    // 5th commit: Create PS2.
    PushOneCommit.Result result2 = amendChange(changeId, "refs/for/master", "b.txt", "b");
    String ps2 = result2.getCommit().name();
    // 6th commit: Add (c5) to PS1.
    CommentInput c5 = newComment("a.txt", "comment 5");
    addComments(changeId, ps1, c5);
    // 7th commit: Add (c6) to PS2.
    CommentInput c6 = newComment("b.txt", "comment 6");
    addComments(changeId, ps2, c6);
    // 8th commit: Create PS3.
    PushOneCommit.Result result3 = amendChange(changeId);
    String ps3 = result3.getCommit().name();
    // 9th commit: Create PS4.
    PushOneCommit.Result result4 = amendChange(changeId, "refs/for/master", "c.txt", "c");
    String ps4 = result4.getCommit().name();
    // 10th commit: Add (c7, c8) to PS4.
    CommentInput c7 = newComment("c.txt", "comment 7");
    CommentInput c8 = newComment("b.txt", "comment 8");
    addComments(changeId, ps4, c7, c8);
    // 11th commit: Add (c9) to PS2.
    CommentInput c9 = newComment("b.txt", "comment 9");
    addComments(changeId, ps2, c9);
    List<CommentInfo> commentsBeforeDelete = getChangeSortedComments(changeId);
    assertThat(commentsBeforeDelete).hasSize(9);
    // PS1 has comments [c1, c2, c3, c4, c5].
    assertThat(getRevisionComments(changeId, ps1)).hasSize(5);
    // PS2 has comments [c6, c9].
    assertThat(getRevisionComments(changeId, ps2)).hasSize(2);
    // PS3 has no comment.
    assertThat(getRevisionComments(changeId, ps3)).hasSize(0);
    // PS4 has comments [c7, c8].
    assertThat(getRevisionComments(changeId, ps4)).hasSize(2);
    setApiUser(admin);
    for (int i = 0; i < commentsBeforeDelete.size(); i++) {
        List<RevCommit> commitsBeforeDelete = new ArrayList<>();
        if (notesMigration.commitChangeWrites()) {
            commitsBeforeDelete = getCommits(id);
        }
        CommentInfo comment = commentsBeforeDelete.get(i);
        String uuid = comment.id;
        int patchSet = comment.patchSet;
        // 'oldComment' has some fields unset compared with 'comment'.
        CommentInfo oldComment = gApi.changes().id(changeId).revision(patchSet).comment(uuid).get();
        DeleteCommentInput input = new DeleteCommentInput("delete comment " + uuid);
        CommentInfo updatedComment = gApi.changes().id(changeId).revision(patchSet).comment(uuid).delete(input);
        String expectedMsg = String.format("Comment removed by: %s; Reason: %s", admin.fullName, input.reason);
        assertThat(updatedComment.message).isEqualTo(expectedMsg);
        oldComment.message = expectedMsg;
        assertThat(updatedComment).isEqualTo(oldComment);
        // Check the NoteDb state after the deletion.
        if (notesMigration.commitChangeWrites()) {
            assertMetaBranchCommitsAfterRewriting(commitsBeforeDelete, id, uuid, expectedMsg);
        }
        comment.message = expectedMsg;
        commentsBeforeDelete.set(i, comment);
        List<CommentInfo> commentsAfterDelete = getChangeSortedComments(changeId);
        assertThat(commentsAfterDelete).isEqualTo(commentsBeforeDelete);
    }
    // Make sure that comments can still be added correctly.
    CommentInput c10 = newComment("a.txt", "comment 10");
    CommentInput c11 = newComment("b.txt", "comment 11");
    CommentInput c12 = newComment("a.txt", "comment 12");
    CommentInput c13 = newComment("c.txt", "comment 13");
    addComments(changeId, ps1, c10);
    addComments(changeId, ps2, c11);
    addComments(changeId, ps3, c12);
    addComments(changeId, ps4, c13);
    assertThat(getChangeSortedComments(changeId)).hasSize(13);
    assertThat(getRevisionComments(changeId, ps1)).hasSize(6);
    assertThat(getRevisionComments(changeId, ps2)).hasSize(3);
    assertThat(getRevisionComments(changeId, ps3)).hasSize(1);
    assertThat(getRevisionComments(changeId, ps4)).hasSize(3);
}
Also used : ArrayList(java.util.ArrayList) Change(com.google.gerrit.reviewdb.client.Change) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 24 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class CommentsIT method postCommentWithUnresolved.

@Test
public void postCommentWithUnresolved() throws Exception {
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "first subject", file, contents);
        PushOneCommit.Result r = push.to("refs/for/master");
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", true);
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        revision(r).review(input);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        assertThat(result).isNotEmpty();
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        assertThat(comment).isEqualTo(infoToInput(file).apply(actual));
        assertThat(comment).isEqualTo(infoToInput(file).apply(getPublishedComment(changeId, revId, actual.id)));
    }
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 25 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class ListMailFilterIT method createChangeAndReplyByEmail.

private ChangeInfo createChangeAndReplyByEmail() throws Exception {
    String changeId = createChangeWithReview();
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    List<CommentInfo> comments = gApi.changes().id(changeId).current().commentsAsList();
    String ts = MailUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(comments.get(0).updated.toInstant(), ZoneId.of("UTC")));
    // Build Message
    MailMessage.Builder b = messageBuilderWithDefaultFields();
    String txt = newPlaintextBody(canonicalWebUrl.get() + "#/c/" + changeInfo._number + "/1", "Test Message", null, null, null);
    b.textContent(txt + textFooterForChange(changeId, ts));
    mailProcessor.process(b.build());
    return changeInfo;
}
Also used : MailMessage(com.google.gerrit.server.mail.receive.MailMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo)

Aggregations

CommentInfo (com.google.gerrit.extensions.common.CommentInfo)33 Test (org.junit.Test)31 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)24 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)23 List (java.util.List)18 ImmutableList (com.google.common.collect.ImmutableList)17 ArrayList (java.util.ArrayList)17 IdString (com.google.gerrit.extensions.restapi.IdString)16 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)12 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)10 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)10 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 Change (com.google.gerrit.reviewdb.client.Change)6 MailMessage (com.google.gerrit.server.mail.receive.MailMessage)6 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)5 Timestamp (java.sql.Timestamp)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 ChangeResource (com.google.gerrit.server.change.ChangeResource)3