Search in sources :

Example 1 with CommentRange

use of com.google.gerrit.reviewdb.client.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method multipleUpdatesIncludingComments.

@Test
public void multipleUpdatesIncludingComments() throws Exception {
    Change c = newChange();
    ChangeUpdate update1 = newUpdate(c, otherUser);
    String uuid1 = "uuid1";
    String message1 = "comment 1";
    CommentRange range1 = new CommentRange(1, 1, 2, 1);
    Timestamp time1 = TimeUtil.nowTs();
    PatchSet.Id psId = c.currentPatchSetId();
    RevCommit tipCommit;
    try (NoteDbUpdateManager updateManager = updateManagerFactory.create(project)) {
        Comment comment1 = newComment(psId, "file1", uuid1, range1, range1.getEndLine(), otherUser, null, time1, message1, (short) 0, "abcd1234abcd1234abcd1234abcd1234abcd1234", false);
        update1.setPatchSetId(psId);
        update1.putComment(Status.PUBLISHED, comment1);
        updateManager.add(update1);
        ChangeUpdate update2 = newUpdate(c, otherUser);
        update2.putApproval("Code-Review", (short) 2);
        updateManager.add(update2);
        updateManager.execute();
    }
    ChangeNotes notes = newNotes(c);
    ObjectId tip = notes.getRevision();
    tipCommit = rw.parseCommit(tip);
    RevCommit commitWithApprovals = tipCommit;
    assertThat(commitWithApprovals).isNotNull();
    RevCommit commitWithComments = commitWithApprovals.getParent(0);
    assertThat(commitWithComments).isNotNull();
    try (ChangeNotesRevWalk rw = ChangeNotesCommit.newRevWalk(repo)) {
        ChangeNotesParser notesWithComments = new ChangeNotesParser(c.getId(), commitWithComments.copy(), rw, noteUtil, args.metrics);
        ChangeNotesState state = notesWithComments.parseAll();
        assertThat(state.approvals()).isEmpty();
        assertThat(state.publishedComments()).hasSize(1);
    }
    try (ChangeNotesRevWalk rw = ChangeNotesCommit.newRevWalk(repo)) {
        ChangeNotesParser notesWithApprovals = new ChangeNotesParser(c.getId(), commitWithApprovals.copy(), rw, noteUtil, args.metrics);
        ChangeNotesState state = notesWithApprovals.parseAll();
        assertThat(state.approvals()).hasSize(1);
        assertThat(state.publishedComments()).hasSize(1);
    }
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) ObjectId(org.eclipse.jgit.lib.ObjectId) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp) ChangeNotesRevWalk(com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 2 with CommentRange

use of com.google.gerrit.reviewdb.client.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentEmptyFilename.

@Test
public void patchLineCommentEmptyFilename() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, otherUser);
    PatchSet.Id psId = c.currentPatchSetId();
    RevId revId = new RevId("abcd1234abcd1234abcd1234abcd1234abcd1234");
    CommentRange range = new CommentRange(1, 2, 3, 4);
    Comment comment = newComment(psId, "", "uuid", range, range.getEndLine(), otherUser, null, TimeUtil.nowTs(), "message", (short) 1, revId.get(), false);
    update.setPatchSetId(psId);
    update.putComment(Status.PUBLISHED, comment);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getComments()).isEqualTo(ImmutableListMultimap.of(revId, comment));
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RevId(com.google.gerrit.reviewdb.client.RevId) Test(org.junit.Test)

Example 3 with CommentRange

use of com.google.gerrit.reviewdb.client.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentsDeleteAllDrafts.

@Test
public void patchLineCommentsDeleteAllDrafts() throws Exception {
    Change c = newChange();
    String uuid = "uuid";
    String rev = "abcd1234abcd1234abcd1234abcd1234abcd1234";
    ObjectId objId = ObjectId.fromString(rev);
    CommentRange range = new CommentRange(1, 1, 2, 1);
    PatchSet.Id psId = c.currentPatchSetId();
    String filename = "filename";
    short side = (short) 1;
    ChangeUpdate update = newUpdate(c, otherUser);
    Timestamp now = TimeUtil.nowTs();
    Comment comment = newComment(psId, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps1", side, rev, false);
    update.setPatchSetId(psId);
    update.putComment(Status.DRAFT, comment);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).hasSize(1);
    assertThat(notes.getDraftCommentNotes().getNoteMap().contains(objId)).isTrue();
    update = newUpdate(c, otherUser);
    now = TimeUtil.nowTs();
    update.setPatchSetId(psId);
    update.deleteComment(comment);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).isEmpty();
    assertThat(notes.getDraftCommentNotes().getNoteMap()).isNull();
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) ObjectId(org.eclipse.jgit.lib.ObjectId) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 4 with CommentRange

use of com.google.gerrit.reviewdb.client.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentMultipleOnePatchsetMultipleFiles.

@Test
public void patchLineCommentMultipleOnePatchsetMultipleFiles() throws Exception {
    Change c = newChange();
    String uuid = "uuid";
    String rev = "abcd1234abcd1234abcd1234abcd1234abcd1234";
    CommentRange range = new CommentRange(1, 1, 2, 1);
    PatchSet.Id psId = c.currentPatchSetId();
    String filename1 = "filename1";
    String filename2 = "filename2";
    short side = (short) 1;
    ChangeUpdate update = newUpdate(c, otherUser);
    Timestamp now = TimeUtil.nowTs();
    Comment comment1 = newComment(psId, filename1, uuid, range, range.getEndLine(), otherUser, null, now, "comment 1", side, rev, false);
    update.setPatchSetId(psId);
    update.putComment(Status.PUBLISHED, comment1);
    update.commit();
    update = newUpdate(c, otherUser);
    Comment comment2 = newComment(psId, filename2, uuid, range, range.getEndLine(), otherUser, null, now, "comment 2", side, rev, false);
    update.setPatchSetId(psId);
    update.putComment(Status.PUBLISHED, comment2);
    update.commit();
    assertThat(newNotes(c).getComments()).containsExactlyEntriesIn(ImmutableListMultimap.of(new RevId(rev), comment1, new RevId(rev), comment2)).inOrder();
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp) RevId(com.google.gerrit.reviewdb.client.RevId) Test(org.junit.Test)

Example 5 with CommentRange

use of com.google.gerrit.reviewdb.client.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentsDeleteAllDraftsForOneRevision.

@Test
public void patchLineCommentsDeleteAllDraftsForOneRevision() throws Exception {
    Change c = newChange();
    String uuid = "uuid";
    String rev1 = "abcd1234abcd1234abcd1234abcd1234abcd1234";
    String rev2 = "abcd4567abcd4567abcd4567abcd4567abcd4567";
    ObjectId objId1 = ObjectId.fromString(rev1);
    ObjectId objId2 = ObjectId.fromString(rev2);
    CommentRange range = new CommentRange(1, 1, 2, 1);
    PatchSet.Id ps1 = c.currentPatchSetId();
    String filename = "filename1";
    short side = (short) 1;
    ChangeUpdate update = newUpdate(c, otherUser);
    Timestamp now = TimeUtil.nowTs();
    Comment comment1 = newComment(ps1, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps1", side, rev1, false);
    update.setPatchSetId(ps1);
    update.putComment(Status.DRAFT, comment1);
    update.commit();
    incrementPatchSet(c);
    PatchSet.Id ps2 = c.currentPatchSetId();
    update = newUpdate(c, otherUser);
    now = TimeUtil.nowTs();
    Comment comment2 = newComment(ps2, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps2", side, rev2, false);
    update.setPatchSetId(ps2);
    update.putComment(Status.DRAFT, comment2);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).hasSize(2);
    update = newUpdate(c, otherUser);
    now = TimeUtil.nowTs();
    update.setPatchSetId(ps2);
    update.deleteComment(comment2);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).hasSize(1);
    NoteMap noteMap = notes.getDraftCommentNotes().getNoteMap();
    assertThat(noteMap.contains(objId1)).isTrue();
    assertThat(noteMap.contains(objId2)).isFalse();
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) ObjectId(org.eclipse.jgit.lib.ObjectId) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) NoteMap(org.eclipse.jgit.notes.NoteMap) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Aggregations

CommentRange (com.google.gerrit.reviewdb.client.CommentRange)32 Change (com.google.gerrit.reviewdb.client.Change)31 Test (org.junit.Test)30 Comment (com.google.gerrit.reviewdb.client.Comment)29 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)27 Timestamp (java.sql.Timestamp)25 RevId (com.google.gerrit.reviewdb.client.RevId)19 ChangeNotesRevWalk (com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk)7 ObjectId (org.eclipse.jgit.lib.ObjectId)7 Note (org.eclipse.jgit.notes.Note)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 Account (com.google.gerrit.reviewdb.client.Account)2 GerritServerId (com.google.gerrit.server.config.GerritServerId)2 RequestId (com.google.gerrit.server.util.RequestId)2 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)1 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 NoteMap (org.eclipse.jgit.notes.NoteMap)1