Search in sources :

Example 26 with CommentRange

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

the class ChangeNotesTest method pushCertificate.

@Test
public void pushCertificate() throws Exception {
    String pushCert = "certificate version 0.1\n" + "pusher This is not a real push cert\n" + "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1\n" + "\n" + "Nor is this a real signature.\n" + "-----END PGP SIGNATURE-----\n";
    // ps2 with push cert
    Change c = newChange();
    PatchSet.Id psId1 = c.currentPatchSetId();
    incrementCurrentPatchSetFieldOnly(c);
    PatchSet.Id psId2 = c.currentPatchSetId();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setPatchSetId(psId2);
    RevCommit commit = tr.commit().message("PS2").create();
    update.setCommit(rw, commit, pushCert);
    update.commit();
    ChangeNotes notes = newNotes(c);
    readNote(notes, commit);
    Map<PatchSet.Id, PatchSet> patchSets = notes.getPatchSets();
    assertThat(patchSets.get(psId1).pushCertificate()).isEmpty();
    assertThat(patchSets.get(psId2).pushCertificate()).hasValue(pushCert);
    assertThat(notes.getHumanComments()).isEmpty();
    // comment on ps2
    update = newUpdate(c, changeOwner);
    update.setPatchSetId(psId2);
    Instant ts = TimeUtil.now();
    update.putComment(HumanComment.Status.PUBLISHED, newComment(psId2, "a.txt", "uuid1", new CommentRange(1, 2, 3, 4), 1, changeOwner, null, ts, "Comment", (short) 1, commit, false));
    update.commit();
    notes = newNotes(c);
    patchSets = notes.getPatchSets();
    assertThat(patchSets.get(psId1).pushCertificate()).isEmpty();
    assertThat(patchSets.get(psId2).pushCertificate()).hasValue(pushCert);
    assertThat(notes.getHumanComments()).isNotEmpty();
}
Also used : Instant(java.time.Instant) CommentRange(com.google.gerrit.entities.CommentRange) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) SubmissionId(com.google.gerrit.entities.SubmissionId) LabelId(com.google.gerrit.entities.LabelId) ObjectId(org.eclipse.jgit.lib.ObjectId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 27 with CommentRange

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

the class ChangeNotesTest method addingPublishedCommentDoesNotCreateNoOpCommitOnNonEmptyDraftRef.

@Test
public void addingPublishedCommentDoesNotCreateNoOpCommitOnNonEmptyDraftRef() throws Exception {
    Change c = newChange();
    ObjectId commitId = 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 draft = newComment(ps1, filename, "uuid1", range, range.getEndLine(), otherUser, null, now, "draft comment on ps1", side, commitId, false);
    update.putComment(HumanComment.Status.DRAFT, draft);
    update.commit();
    String draftRef = refsDraftComments(c.getId(), otherUser.getAccountId());
    ObjectId old = exactRefAllUsers(draftRef);
    assertThat(old).isNotNull();
    update = newUpdate(c, otherUser);
    HumanComment pub = newComment(ps1, filename, "uuid2", range, range.getEndLine(), otherUser, null, now, "comment on ps1", side, commitId, false);
    update.putComment(HumanComment.Status.PUBLISHED, pub);
    update.commit();
    assertThat(exactRefAllUsers(draftRef)).isEqualTo(old);
}
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 28 with CommentRange

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

the class ChangeNotesTest method putCommentsForMultipleRevisions.

@Test
public void putCommentsForMultipleRevisions() 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;
    incrementPatchSet(c);
    PatchSet.Id ps2 = c.currentPatchSetId();
    ChangeUpdate update = newUpdate(c, otherUser);
    update.setPatchSetId(ps2);
    Instant now = TimeUtil.now();
    HumanComment comment1 = newComment(ps1, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps1", side, commitId1, false);
    HumanComment comment2 = newComment(ps2, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps2", side, commitId2, false);
    update.putComment(HumanComment.Status.DRAFT, comment1);
    update.putComment(HumanComment.Status.DRAFT, comment2);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).hasSize(2);
    assertThat(notes.getHumanComments()).isEmpty();
    update = newUpdate(c, otherUser);
    update.setPatchSetId(ps2);
    update.putComment(HumanComment.Status.PUBLISHED, comment1);
    update.putComment(HumanComment.Status.PUBLISHED, comment2);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).isEmpty();
    assertThat(notes.getHumanComments()).hasSize(2);
}
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)

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