Search in sources :

Example 6 with CommentRange

use of com.google.gerrit.entities.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentNotesFormatWeirdUser.

@Test
public void patchLineCommentNotesFormatWeirdUser() throws Exception {
    Account.Builder account = Account.builder(Account.id(3), TimeUtil.now());
    account.setFullName("Weird\n\u0002<User>\n");
    account.setPreferredEmail(" we\r\nird@ex>ample<.com");
    accountCache.put(account.build());
    IdentifiedUser user = userFactory.create(Account.id(3));
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, user);
    String uuid = "uuid";
    CommentRange range = new CommentRange(1, 1, 2, 1);
    Instant time = TimeUtil.now();
    PatchSet.Id psId = c.currentPatchSetId();
    HumanComment comment = newComment(psId, "file1", uuid, range, range.getEndLine(), user, null, time, "comment", (short) 1, ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"), false);
    update.setPatchSetId(psId);
    update.putComment(HumanComment.Status.PUBLISHED, comment);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(comment.getCommitId(), comment));
}
Also used : Account(com.google.gerrit.entities.Account) Instant(java.time.Instant) CommentRange(com.google.gerrit.entities.CommentRange) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 7 with CommentRange

use of com.google.gerrit.entities.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentNotesFormatMultiplePatchSetsSameCommitId.

@Test
public void patchLineCommentNotesFormatMultiplePatchSetsSameCommitId() throws Exception {
    Change c = newChange();
    PatchSet.Id psId1 = c.currentPatchSetId();
    incrementPatchSet(c);
    PatchSet.Id psId2 = c.currentPatchSetId();
    String uuid1 = "uuid1";
    String uuid2 = "uuid2";
    String uuid3 = "uuid3";
    String message1 = "comment 1";
    String message2 = "comment 2";
    String message3 = "comment 3";
    CommentRange range1 = new CommentRange(1, 1, 2, 1);
    CommentRange range2 = new CommentRange(2, 1, 3, 1);
    Instant time = TimeUtil.now();
    ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
    HumanComment comment1 = newComment(psId1, "file1", uuid1, range1, range1.getEndLine(), otherUser, null, time, message1, (short) 0, commitId, false);
    HumanComment comment2 = newComment(psId1, "file1", uuid2, range2, range2.getEndLine(), otherUser, null, time, message2, (short) 0, commitId, false);
    HumanComment comment3 = newComment(psId2, "file1", uuid3, range1, range1.getEndLine(), otherUser, null, time, message3, (short) 0, commitId, false);
    ChangeUpdate update = newUpdate(c, otherUser);
    update.setPatchSetId(psId2);
    update.putComment(HumanComment.Status.PUBLISHED, comment3);
    update.putComment(HumanComment.Status.PUBLISHED, comment2);
    update.putComment(HumanComment.Status.PUBLISHED, comment1);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment1, commitId, comment2, commitId, comment3));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) Instant(java.time.Instant) CommentRange(com.google.gerrit.entities.CommentRange) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 8 with CommentRange

use of com.google.gerrit.entities.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentMultipleDraftsSameSidePublishOne.

@Test
public void patchLineCommentMultipleDraftsSameSidePublishOne() throws Exception {
    Change c = newChange();
    String uuid1 = "uuid1";
    String uuid2 = "uuid2";
    ObjectId commitId = ObjectId.fromString("abcd4567abcd4567abcd4567abcd4567abcd4567");
    CommentRange range1 = new CommentRange(1, 1, 2, 2);
    CommentRange range2 = new CommentRange(2, 2, 3, 3);
    String filename = "filename1";
    short side = (short) 1;
    Instant now = TimeUtil.now();
    PatchSet.Id psId = c.currentPatchSetId();
    // Write two drafts on the same side of one patch set.
    ChangeUpdate update = newUpdate(c, otherUser);
    update.setPatchSetId(psId);
    HumanComment comment1 = newComment(psId, filename, uuid1, range1, range1.getEndLine(), otherUser, null, now, "comment on ps1", side, commitId, false);
    HumanComment comment2 = newComment(psId, filename, uuid2, range2, range2.getEndLine(), otherUser, null, now, "other on ps1", side, commitId, false);
    update.putComment(HumanComment.Status.DRAFT, comment1);
    update.putComment(HumanComment.Status.DRAFT, comment2);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1, commitId, comment2)).inOrder();
    assertThat(notes.getHumanComments()).isEmpty();
    // Publish first draft.
    update = newUpdate(c, otherUser);
    update.setPatchSetId(psId);
    update.putComment(HumanComment.Status.PUBLISHED, comment1);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment2));
    assertThat(notes.getHumanComments()).containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) Instant(java.time.Instant) CommentRange(com.google.gerrit.entities.CommentRange) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 9 with CommentRange

use of com.google.gerrit.entities.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentsDeleteAllDraftsForOneRevision.

@Test
public void patchLineCommentsDeleteAllDraftsForOneRevision() throws Exception {
    Change c = newChange();
    String uuid = "uuid";
    ObjectId commitId1 = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
    ObjectId commitId2 = ObjectId.fromString("abcd4567abcd4567abcd4567abcd4567abcd4567");
    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);
    Instant now = TimeUtil.now();
    HumanComment comment1 = newComment(ps1, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps1", side, commitId1, false);
    update.setPatchSetId(ps1);
    update.putComment(HumanComment.Status.DRAFT, comment1);
    update.commit();
    incrementPatchSet(c);
    PatchSet.Id ps2 = c.currentPatchSetId();
    update = newUpdate(c, otherUser);
    now = TimeUtil.now();
    HumanComment comment2 = newComment(ps2, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps2", side, commitId2, false);
    update.setPatchSetId(ps2);
    update.putComment(HumanComment.Status.DRAFT, comment2);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).hasSize(2);
    update = newUpdate(c, otherUser);
    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(commitId1)).isTrue();
    assertThat(noteMap.contains(commitId2)).isFalse();
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) Instant(java.time.Instant) CommentRange(com.google.gerrit.entities.CommentRange) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) NoteMap(org.eclipse.jgit.notes.NoteMap) HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 10 with CommentRange

use of com.google.gerrit.entities.CommentRange in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchSetStates.

@Test
public void patchSetStates() throws Exception {
    Change c = newChange();
    PatchSet.Id psId1 = c.currentPatchSetId();
    incrementCurrentPatchSetFieldOnly(c);
    PatchSet.Id psId2 = c.currentPatchSetId();
    RevCommit commit = tr.commit().message("PS2").create();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setCommit(rw, commit);
    update.putApproval(LabelId.CODE_REVIEW, (short) 1);
    update.setChangeMessage("This is a message");
    update.putComment(HumanComment.Status.PUBLISHED, newComment(c.currentPatchSetId(), "a.txt", "uuid1", new CommentRange(1, 2, 3, 4), 1, changeOwner, null, TimeUtil.now(), "Comment", (short) 1, commit, false));
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getPatchSets().keySet()).containsExactly(psId1, psId2);
    assertThat(notes.getApprovals()).isNotEmpty();
    assertThat(notes.getChangeMessages()).isNotEmpty();
    assertThat(notes.getHumanComments()).isNotEmpty();
    // publish ps2
    update = newUpdate(c, changeOwner);
    update.setPatchSetState(PatchSetState.PUBLISHED);
    update.commit();
    // delete ps2
    update = newUpdate(c, changeOwner);
    update.setPatchSetState(PatchSetState.DELETED);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getPatchSets().keySet()).containsExactly(psId1);
    assertThat(notes.getApprovals()).isEmpty();
    assertThat(notes.getChangeMessages()).isEmpty();
    assertThat(notes.getHumanComments()).isEmpty();
}
Also used : CommentRange(com.google.gerrit.entities.CommentRange) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

Change (com.google.gerrit.entities.Change)28 CommentRange (com.google.gerrit.entities.CommentRange)28 Test (org.junit.Test)28 HumanComment (com.google.gerrit.entities.HumanComment)25 ObjectId (org.eclipse.jgit.lib.ObjectId)24 PatchSet (com.google.gerrit.entities.PatchSet)23 Instant (java.time.Instant)19 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 LabelId (com.google.gerrit.entities.LabelId)2 SubmissionId (com.google.gerrit.entities.SubmissionId)2 Account (com.google.gerrit.entities.Account)1 ChangeMessage (com.google.gerrit.entities.ChangeMessage)1 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 ChangeNotesRevWalk (com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk)1 NoteMap (org.eclipse.jgit.notes.NoteMap)1