Search in sources :

Example 36 with CommentInfo

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

the class CommentsIT method listChangeComments.

@Test
public void listChangeComments() throws Exception {
    PushOneCommit.Result r1 = createChange();
    PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "new cntent", r1.getChangeId()).to("refs/for/master");
    CommentsUtil.addComment(gApi, r1, "nit: trailing whitespace");
    CommentsUtil.addComment(gApi, r2, "typo: content");
    Map<String, List<CommentInfo>> actual = gApi.changes().id(r2.getChangeId()).commentsRequest().get();
    assertThat(actual.keySet()).containsExactly(FILE_NAME);
    List<CommentInfo> comments = actual.get(FILE_NAME);
    assertThat(comments).hasSize(2);
    // Comment context is disabled by default
    assertThat(comments.stream().filter(c -> c.contextLines != null)).isEmpty();
    CommentInfo c1 = comments.get(0);
    assertThat(c1.author._accountId).isEqualTo(user.id().get());
    assertThat(c1.patchSet).isEqualTo(1);
    assertThat(c1.message).isEqualTo("nit: trailing whitespace");
    assertThat(c1.side).isNull();
    assertThat(c1.line).isEqualTo(1);
    CommentInfo c2 = comments.get(1);
    assertThat(c2.author._accountId).isEqualTo(user.id().get());
    assertThat(c2.patchSet).isEqualTo(2);
    assertThat(c2.message).isEqualTo("typo: content");
    assertThat(c2.side).isNull();
    assertThat(c2.line).isEqualTo(1);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 37 with CommentInfo

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

the class CommentsIT method publishCommentsAllRevisions.

@Test
public void publishCommentsAllRevisions() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "initial content\n", changeId).to("refs/heads/master");
    PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "old boring content\n").to("refs/for/master");
    PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "new interesting\ncntent\n", r1.getChangeId()).to("refs/for/master");
    addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 10), "Is it that bad?"));
    addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, createLineRange(0, 7), "what happened to this?"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 15), "better now"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 2, "typo: content"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, 1, "comment 1 on base"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, 2, "comment 2 on base"));
    PushOneCommit.Result other = createChange();
    // Drafts on other changes aren't returned.
    addDraft(other.getChangeId(), other.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 1, "unrelated comment"));
    requestScopeOperations.setApiUser(admin.id());
    // Drafts by other users aren't returned.
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 2, "oops"));
    requestScopeOperations.setApiUser(user.id());
    ReviewInput reviewInput = new ReviewInput();
    reviewInput.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
    reviewInput.message = "comments";
    gApi.changes().id(r2.getChangeId()).current().review(reviewInput);
    assertThat(gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).drafts()).isEmpty();
    Map<String, List<CommentInfo>> ps1Map = gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).comments();
    assertThat(ps1Map.keySet()).containsExactly(FILE_NAME);
    List<CommentInfo> ps1List = ps1Map.get(FILE_NAME);
    assertThat(ps1List).hasSize(2);
    assertThat(ps1List.get(0).message).isEqualTo("what happened to this?");
    assertThat(ps1List.get(0).side).isEqualTo(Side.PARENT);
    assertThat(ps1List.get(1).message).isEqualTo("Is it that bad?");
    assertThat(ps1List.get(1).side).isNull();
    assertThat(gApi.changes().id(r2.getChangeId()).revision(r2.getCommit().name()).drafts()).isEmpty();
    Map<String, List<CommentInfo>> ps2Map = gApi.changes().id(r2.getChangeId()).revision(r2.getCommit().name()).comments();
    assertThat(ps2Map.keySet()).containsExactly(FILE_NAME);
    List<CommentInfo> ps2List = ps2Map.get(FILE_NAME);
    assertThat(ps2List).hasSize(4);
    assertThat(ps2List.get(0).message).isEqualTo("comment 1 on base");
    assertThat(ps2List.get(1).message).isEqualTo("comment 2 on base");
    assertThat(ps2List.get(2).message).isEqualTo("better now");
    assertThat(ps2List.get(3).message).isEqualTo("typo: content");
    List<Message> messages = email.getMessages(r2.getChangeId(), "comment");
    assertThat(messages).hasSize(1);
    String url = canonicalWebUrl.get();
    int c = r1.getChange().getId().get();
    assertThat(extractComments(messages.get(0).body())).isEqualTo("Patch Set 2:\n" + "\n" + "(6 comments)\n" + "\n" + "comments\n" + "\n" + "File a.txt:\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps1List.get(0).id + " \n" + "PS1, Line 1: initial\n" + "what happened to this?\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps1List.get(1).id + " \n" + "PS1, Line 1: boring\n" + "Is it that bad?\n" + "\n" + "\n" + "File a.txt:\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(0).id + " \n" + "PS2, Line 1: initial content\n" + "comment 1 on base\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(1).id + " \n" + "PS2, Line 2: \n" + "comment 2 on base\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(2).id + " \n" + "PS2, Line 1: interesting\n" + "better now\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(3).id + " \n" + "PS2, Line 2: cntent\n" + "typo: content\n" + "\n" + "\n");
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) 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 38 with CommentInfo

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

the class CommentsIT method listChangeDrafts.

@Test
public void listChangeDrafts() throws Exception {
    PushOneCommit.Result r1 = createChange();
    PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "new content", r1.getChangeId()).to("refs/for/master");
    requestScopeOperations.setApiUser(admin.id());
    addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 1, "nit: trailing whitespace"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 1, "typo: content"));
    requestScopeOperations.setApiUser(user.id());
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 1, "+1, please fix"));
    requestScopeOperations.setApiUser(admin.id());
    Map<String, List<CommentInfo>> actual = gApi.changes().id(r1.getChangeId()).drafts();
    assertThat(actual.keySet()).containsExactly(FILE_NAME);
    List<CommentInfo> comments = actual.get(FILE_NAME);
    assertThat(comments).hasSize(2);
    CommentInfo c1 = comments.get(0);
    assertThat(c1.author).isNull();
    assertThat(c1.patchSet).isEqualTo(1);
    assertThat(c1.message).isEqualTo("nit: trailing whitespace");
    assertThat(c1.side).isNull();
    assertThat(c1.line).isEqualTo(1);
    CommentInfo c2 = comments.get(1);
    assertThat(c2.author).isNull();
    assertThat(c2.patchSet).isEqualTo(2);
    assertThat(c2.message).isEqualTo("typo: content");
    assertThat(c2.side).isNull();
    assertThat(c2.line).isEqualTo(1);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 39 with CommentInfo

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

the class CommentsIT method commitsInDraftCommentsRefHaveNoParent.

/**
 * This test makes sure that the commits in the refs/draft-comments ref in NoteDb have no parent
 * commits. This is important so that each new draft update (add, modify, delete) does not keep
 * track of previous history.
 */
@Test
public void commitsInDraftCommentsRefHaveNoParent() throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    String revId = r.getCommit().getName();
    String draftRefName = RefNames.refsDraftComments(r.getChange().getId(), user.id());
    DraftInput comment1 = CommentsUtil.newDraft("file_1", Side.REVISION, 1, "comment 1");
    CommentInfo commentInfo1 = addDraft(changeId, revId, comment1);
    assertThat(getHeadOfDraftCommentsRef(draftRefName).getParentCount()).isEqualTo(0);
    DraftInput comment2 = CommentsUtil.newDraft("file_2", Side.REVISION, 2, "comment 2");
    CommentInfo commentInfo2 = addDraft(changeId, revId, comment2);
    assertThat(getHeadOfDraftCommentsRef(draftRefName).getParentCount()).isEqualTo(0);
    deleteDraft(changeId, revId, commentInfo1.id);
    assertThat(getHeadOfDraftCommentsRef(draftRefName).getParentCount()).isEqualTo(0);
    assertThat(getDraftComments(changeId, revId).values().stream().flatMap(List::stream).map(commentInfo -> commentInfo.message)).containsExactly("comment 2");
    deleteDraft(changeId, revId, commentInfo2.id);
    assertThat(projectOperations.project(allUsers).hasHead(draftRefName)).isFalse();
    assertThat(getDraftComments(changeId, revId).values().stream().flatMap(List::stream)).isEmpty();
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 40 with CommentInfo

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

the class CommentsIT method createDraft.

@Test
public void createDraft() throws Exception {
    for (Integer line : lines) {
        PushOneCommit.Result r = createChange();
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        String path = "file1";
        DraftInput comment = CommentsUtil.newDraft(path, Side.REVISION, line, "comment 1");
        addDraft(changeId, revId, comment);
        Map<String, List<CommentInfo>> result = getDraftComments(changeId, revId);
        assertThat(result).hasSize(1);
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
        List<CommentInfo> list = getDraftCommentsAsList(changeId);
        assertThat(list).hasSize(1);
        actual = list.get(0);
        assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
    }
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

CommentInfo (com.google.gerrit.extensions.common.CommentInfo)186 Test (org.junit.Test)178 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)164 Change (com.google.gerrit.entities.Change)120 PatchSet (com.google.gerrit.entities.PatchSet)62 RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)56 List (java.util.List)51 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)47 ImmutableList (com.google.common.collect.ImmutableList)46 IdString (com.google.gerrit.extensions.restapi.IdString)34 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)27 ArrayList (java.util.ArrayList)26 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)25 Collectors.toList (java.util.stream.Collectors.toList)25 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)24 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)22 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)21 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)20 CommentInfoSubject.assertThatList (com.google.gerrit.extensions.common.testing.CommentInfoSubject.assertThatList)19 MailMessage (com.google.gerrit.mail.MailMessage)13