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);
}
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);
}
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");
}
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}");
}
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();
}
Aggregations