Search in sources :

Example 1 with PatchLineComment

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

the class ChangeRebuilderIT method rebuildEntitiesCreatedByImpersonation.

@Test
public void rebuildEntitiesCreatedByImpersonation() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getPatchSetId().getParentKey();
    PatchSet.Id psId = new PatchSet.Id(id, 1);
    String prefix = "/changes/" + id + "/revisions/current/";
    // For each of the entities that have a real user field, create one entity
    // without impersonation and one with.
    CommentInput ci = new CommentInput();
    ci.path = Patch.COMMIT_MSG;
    ci.side = Side.REVISION;
    ci.line = 1;
    ci.message = "comment without impersonation";
    ReviewInput ri = new ReviewInput();
    ri.label("Code-Review", -1);
    ri.message = "message without impersonation";
    ri.drafts = DraftHandling.KEEP;
    ri.comments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
    userRestSession.post(prefix + "review", ri).assertOK();
    DraftInput di = new DraftInput();
    di.path = Patch.COMMIT_MSG;
    di.side = Side.REVISION;
    di.line = 1;
    di.message = "draft without impersonation";
    userRestSession.put(prefix + "drafts", di).assertCreated();
    allowRunAs();
    try {
        Header runAs = new BasicHeader("X-Gerrit-RunAs", user.id.toString());
        ci.message = "comment with impersonation";
        ri.message = "message with impersonation";
        ri.label("Code-Review", 1);
        adminRestSession.postWithHeader(prefix + "review", ri, runAs).assertOK();
        di.message = "draft with impersonation";
        adminRestSession.putWithHeader(prefix + "drafts", runAs, di).assertCreated();
    } finally {
        removeRunAs();
    }
    List<ChangeMessage> msgs = Ordering.natural().onResultOf(ChangeMessage::getWrittenOn).sortedCopy(db.changeMessages().byChange(id));
    assertThat(msgs).hasSize(3);
    assertThat(msgs.get(1).getMessage()).endsWith("message without impersonation");
    assertThat(msgs.get(1).getAuthor()).isEqualTo(user.id);
    assertThat(msgs.get(1).getRealAuthor()).isEqualTo(user.id);
    assertThat(msgs.get(2).getMessage()).endsWith("message with impersonation");
    assertThat(msgs.get(2).getAuthor()).isEqualTo(user.id);
    assertThat(msgs.get(2).getRealAuthor()).isEqualTo(admin.id);
    List<PatchSetApproval> psas = db.patchSetApprovals().byChange(id).toList();
    assertThat(psas).hasSize(1);
    assertThat(psas.get(0).getLabel()).isEqualTo("Code-Review");
    assertThat(psas.get(0).getValue()).isEqualTo(1);
    assertThat(psas.get(0).getAccountId()).isEqualTo(user.id);
    assertThat(psas.get(0).getRealAccountId()).isEqualTo(admin.id);
    Ordering<PatchLineComment> commentOrder = Ordering.natural().onResultOf(PatchLineComment::getWrittenOn);
    List<PatchLineComment> drafts = commentOrder.sortedCopy(db.patchComments().draftByPatchSetAuthor(psId, user.id));
    assertThat(drafts).hasSize(2);
    assertThat(drafts.get(0).getMessage()).isEqualTo("draft without impersonation");
    assertThat(drafts.get(0).getAuthor()).isEqualTo(user.id);
    assertThat(drafts.get(0).getRealAuthor()).isEqualTo(user.id);
    assertThat(drafts.get(1).getMessage()).isEqualTo("draft with impersonation");
    assertThat(drafts.get(1).getAuthor()).isEqualTo(user.id);
    assertThat(drafts.get(1).getRealAuthor()).isEqualTo(admin.id);
    List<PatchLineComment> pub = commentOrder.sortedCopy(db.patchComments().publishedByPatchSet(psId));
    assertThat(pub).hasSize(2);
    assertThat(pub.get(0).getMessage()).isEqualTo("comment without impersonation");
    assertThat(pub.get(0).getAuthor()).isEqualTo(user.id);
    assertThat(pub.get(0).getRealAuthor()).isEqualTo(user.id);
    assertThat(pub.get(1).getMessage()).isEqualTo("comment with impersonation");
    assertThat(pub.get(1).getAuthor()).isEqualTo(user.id);
    assertThat(pub.get(1).getRealAuthor()).isEqualTo(admin.id);
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ObjectId(org.eclipse.jgit.lib.ObjectId) BasicHeader(org.apache.http.message.BasicHeader) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with PatchLineComment

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

the class CommentsUtil method deleteCommentByRewritingHistory.

public void deleteCommentByRewritingHistory(ReviewDb db, ChangeUpdate update, Comment.Key commentKey, PatchSet.Id psId, String newMessage) throws OrmException {
    if (PrimaryStorage.of(update.getChange()).equals(PrimaryStorage.REVIEW_DB)) {
        PatchLineComment.Key key = new PatchLineComment.Key(new Patch.Key(psId, commentKey.filename), commentKey.uuid);
        if (db instanceof BatchUpdateReviewDb) {
            db = ((BatchUpdateReviewDb) db).unsafeGetDelegate();
        }
        db = ReviewDbUtil.unwrapDb(db);
        PatchLineComment patchLineComment = db.patchComments().get(key);
        if (!patchLineComment.getStatus().equals(PUBLISHED)) {
            throw new OrmException(String.format("comment %s is not published", key));
        }
        patchLineComment.setMessage(newMessage);
        db.patchComments().upsert(Collections.singleton(patchLineComment));
    }
    update.deleteCommentByRewritingHistory(commentKey.uuid, newMessage);
}
Also used : BatchUpdateReviewDb(com.google.gerrit.server.update.BatchUpdateReviewDb) PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) OrmException(com.google.gwtorm.server.OrmException) Patch(com.google.gerrit.reviewdb.client.Patch)

Example 3 with PatchLineComment

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

the class ChangeBundleTest method diffPatchLineCommentKeySets.

@Test
public void diffPatchLineCommentKeySets() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    int id = c.getId().get();
    PatchLineComment c1 = new PatchLineComment(new PatchLineComment.Key(new Patch.Key(c.currentPatchSetId(), "filename1"), "uuid1"), 5, accountId, null, TimeUtil.nowTs());
    PatchLineComment c2 = new PatchLineComment(new PatchLineComment.Key(new Patch.Key(c.currentPatchSetId(), "filename2"), "uuid2"), 5, accountId, null, TimeUtil.nowTs());
    ChangeBundle b1 = new ChangeBundle(c, messages(), latest(c), approvals(), comments(c1), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c, messages(), latest(c), approvals(), comments(c2), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "PatchLineComment.Key sets differ:" + " [" + id + ",1,filename1,uuid1] only in A;" + " [" + id + ",1,filename2,uuid2] only in B");
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 4 with PatchLineComment

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

the class ChangeBundleTest method diffPatchLineComments.

@Test
public void diffPatchLineComments() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    PatchLineComment c1 = new PatchLineComment(new PatchLineComment.Key(new Patch.Key(c.currentPatchSetId(), "filename"), "uuid"), 5, accountId, null, TimeUtil.nowTs());
    PatchLineComment c2 = clone(c1);
    ChangeBundle b1 = new ChangeBundle(c, messages(), latest(c), approvals(), comments(c1), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c, messages(), latest(c), approvals(), comments(c2), reviewers(), REVIEW_DB);
    assertNoDiffs(b1, b2);
    c2.setStatus(PatchLineComment.Status.PUBLISHED);
    assertDiffs(b1, b2, "status differs for PatchLineComment.Key " + c.getId() + ",1,filename,uuid: {d} != {P}");
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 5 with PatchLineComment

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

the class ChangeRebuilderIT method ignorePatchLineCommentsOnPatchSet0.

@Test
public void ignorePatchLineCommentsOnPatchSet0() throws Exception {
    PushOneCommit.Result r = createChange();
    Change change = r.getChange().change();
    Change.Id id = change.getId();
    PatchLineComment comment = new PatchLineComment(new PatchLineComment.Key(new Patch.Key(new PatchSet.Id(id, 0), PushOneCommit.FILE_NAME), "uuid"), 0, user.getId(), null, TimeUtil.nowTs());
    comment.setSide((short) 1);
    comment.setMessage("message");
    comment.setStatus(PatchLineComment.Status.PUBLISHED);
    db.patchComments().insert(Collections.singleton(comment));
    indexer.index(db, change.getProject(), id);
    checker.rebuildAndCheckChanges(id);
    setNotesMigration(true, true);
    ChangeNotes notes = notesFactory.create(db, project, id);
    assertThat(notes.getComments()).isEmpty();
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

PatchLineComment (com.google.gerrit.reviewdb.client.PatchLineComment)9 Change (com.google.gerrit.reviewdb.client.Change)6 Test (org.junit.Test)6 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)2 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)2 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)1 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)1 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)1 Patch (com.google.gerrit.reviewdb.client.Patch)1 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)1 BatchUpdateReviewDb (com.google.gerrit.server.update.BatchUpdateReviewDb)1 OrmException (com.google.gwtorm.server.OrmException)1 Timestamp (java.sql.Timestamp)1 Header (org.apache.http.Header)1 BasicHeader (org.apache.http.message.BasicHeader)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1