use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class DeleteDraftPatchSetIT method deleteDraftPS2.
@Test
public void deleteDraftPS2() throws Exception {
String changeId = createDraftChangeWith2PS();
ReviewInput rin = new ReviewInput();
rin.message = "Change message";
CommentInput cin = new CommentInput();
cin.line = 1;
cin.patchSet = 1;
cin.path = PushOneCommit.FILE_NAME;
cin.side = Side.REVISION;
cin.message = "Inline comment";
rin.comments = new HashMap<>();
rin.comments.put(cin.path, ImmutableList.of(cin));
gApi.changes().id(changeId).revision(1).review(rin);
ChangeData cd = getChange(changeId);
PatchSet.Id delPsId = new PatchSet.Id(cd.getId(), 2);
PatchSet ps = cd.patchSet(delPsId);
deletePatchSet(changeId, ps);
cd = getChange(changeId);
assertThat(cd.patchSets()).hasSize(1);
assertThat(Iterables.getOnlyElement(cd.patchSets()).getId().get()).isEqualTo(1);
// Other entities based on deleted patch sets are also deleted.
for (ChangeMessage m : cd.messages()) {
assertThat(m.getPatchSetId()).named(m.toString()).isNotEqualTo(delPsId);
}
for (Comment c : cd.publishedComments()) {
assertThat(c.key.patchSetId).named(c.toString()).isNotEqualTo(delPsId.get());
}
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class NoteDbPrimaryIT method rebuildReviewDb.
@Test
public void rebuildReviewDb() throws Exception {
Change c = createChange().getChange().change();
Change.Id id = c.getId();
CommentInput cin = new CommentInput();
cin.line = 1;
cin.message = "Published comment";
ReviewInput rin = ReviewInput.approve();
rin.comments = ImmutableMap.of(PushOneCommit.FILE_NAME, ImmutableList.of(cin));
gApi.changes().id(id.get()).current().review(ReviewInput.approve());
DraftInput din = new DraftInput();
din.path = PushOneCommit.FILE_NAME;
din.line = 1;
din.message = "Draft comment";
gApi.changes().id(id.get()).current().createDraft(din);
gApi.changes().id(id.get()).current().review(ReviewInput.approve());
gApi.changes().id(id.get()).current().createDraft(din);
assertThat(db.changeMessages().byChange(id)).isNotEmpty();
assertThat(db.patchSets().byChange(id)).isNotEmpty();
assertThat(db.patchSetApprovals().byChange(id)).isNotEmpty();
assertThat(db.patchComments().byChange(id)).isNotEmpty();
ChangeBundle noteDbBundle = ChangeBundle.fromNotes(commentsUtil, notesFactory.create(db, project, id));
setNoteDbPrimary(id);
db.changeMessages().delete(db.changeMessages().byChange(id));
db.patchSets().delete(db.patchSets().byChange(id));
db.patchSetApprovals().delete(db.patchSetApprovals().byChange(id));
db.patchComments().delete(db.patchComments().byChange(id));
ChangeMessage bogusMessage = ChangeMessagesUtil.newMessage(c.currentPatchSetId(), identifiedUserFactory.create(admin.getId()), TimeUtil.nowTs(), "some message", null);
db.changeMessages().insert(Collections.singleton(bogusMessage));
rebuilderWrapper.rebuildReviewDb(db, project, id);
assertThat(db.changeMessages().byChange(id)).isNotEmpty();
assertThat(db.patchSets().byChange(id)).isNotEmpty();
assertThat(db.patchSetApprovals().byChange(id)).isNotEmpty();
assertThat(db.patchComments().byChange(id)).isNotEmpty();
ChangeBundle reviewDbBundle = bundleReader.fromReviewDb(ReviewDbUtil.unwrapDb(db), id);
assertThat(reviewDbBundle.differencesFrom(noteDbBundle)).isEmpty();
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method rebuildAutomaticallyWithinBatchUpdate.
@Test
public void rebuildAutomaticallyWithinBatchUpdate() throws Exception {
setNotesMigration(true, true);
PushOneCommit.Result r = createChange();
final Change.Id id = r.getPatchSetId().getParentKey();
assertChangeUpToDate(true, id);
// Update ReviewDb and NoteDb, then revert the corresponding NoteDb change
// to simulate it failing.
NoteDbChangeState oldState = NoteDbChangeState.parse(getUnwrappedDb().changes().get(id));
String topic = name("a-topic");
gApi.changes().id(id.get()).topic(topic);
try (Repository repo = repoManager.openRepository(project)) {
new TestRepository<>(repo).update(RefNames.changeMetaRef(id), oldState.getChangeMetaId());
}
assertChangeUpToDate(false, id);
// Next NoteDb read comes inside the transaction started by BatchUpdate. In
// reality this could be caused by a failed update happening between when
// the change is parsed by ChangesCollection and when the BatchUpdate
// executes. We simulate it here by using BatchUpdate directly and not going
// through an API handler.
final String msg = "message from BatchUpdate";
try (BatchUpdate bu = batchUpdateFactory.create(db, project, identifiedUserFactory.create(user.getId()), TimeUtil.nowTs())) {
bu.addOp(id, new BatchUpdateOp() {
@Override
public boolean updateChange(ChangeContext ctx) throws OrmException {
PatchSet.Id psId = ctx.getChange().currentPatchSetId();
ChangeMessage cm = new ChangeMessage(new ChangeMessage.Key(id, ChangeUtil.messageUuid()), ctx.getAccountId(), ctx.getWhen(), psId);
cm.setMessage(msg);
ctx.getDb().changeMessages().insert(Collections.singleton(cm));
ctx.getUpdate(psId).setChangeMessage(msg);
return true;
}
});
try {
bu.execute();
fail("expected update to fail");
} catch (UpdateException e) {
assertThat(e.getMessage()).contains("cannot copy ChangeNotesState");
}
}
// TODO(dborowitz): Re-enable these assertions once we fix auto-rebuilding
// in the BatchUpdate path.
//// As an implementation detail, change wasn't actually rebuilt inside the
//// BatchUpdate transaction, but it was rebuilt during read for the
//// subsequent reindex. Thus it's impossible to actually observe an
//// out-of-date state in the caller.
//assertChangeUpToDate(true, id);
//// Check that the bundles are equal.
//ChangeNotes notes = notesFactory.create(dbProvider.get(), project, id);
//ChangeBundle actual = ChangeBundle.fromNotes(commentsUtil, notes);
//ChangeBundle expected = bundleReader.fromReviewDb(getUnwrappedDb(), id);
//assertThat(actual.differencesFrom(expected)).isEmpty();
//assertThat(
// Iterables.transform(
// notes.getChangeMessages(),
// ChangeMessage::getMessage))
// .contains(msg);
//assertThat(actual.getChange().getTopic()).isEqualTo(topic);
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class MergedByPushOp method updateChange.
@Override
public boolean updateChange(ChangeContext ctx) throws OrmException, IOException {
change = ctx.getChange();
correctBranch = refName.equals(change.getDest().get());
if (!correctBranch) {
return false;
}
if (patchSetProvider != null) {
// Caller might have also arranged for construction of a new patch set
// that is not present in the old notes so we can't use PatchSetUtil.
patchSet = patchSetProvider.get();
} else {
patchSet = checkNotNull(psUtil.get(ctx.getDb(), ctx.getNotes(), psId), "patch set %s not found", psId);
}
info = getPatchSetInfo(ctx);
ChangeUpdate update = ctx.getUpdate(psId);
Change.Status status = change.getStatus();
if (status == Change.Status.MERGED) {
return true;
}
if (status.isOpen()) {
change.setCurrentPatchSet(info);
change.setStatus(Change.Status.MERGED);
// we cannot reconstruct the submit records for when this change was
// submitted, this is why we must fix the status
update.fixStatus(Change.Status.MERGED);
update.setCurrentPatchSet();
}
StringBuilder msgBuf = new StringBuilder();
msgBuf.append("Change has been successfully pushed");
if (!refName.equals(change.getDest().get())) {
msgBuf.append(" into ");
if (refName.startsWith(Constants.R_HEADS)) {
msgBuf.append("branch ");
msgBuf.append(Repository.shortenRefName(refName));
} else {
msgBuf.append(refName);
}
}
msgBuf.append(".");
ChangeMessage msg = ChangeMessagesUtil.newMessage(psId, ctx.getUser(), ctx.getWhen(), msgBuf.toString(), ChangeMessagesUtil.TAG_MERGED);
cmUtil.addChangeMessage(ctx.getDb(), update, msg);
PatchSetApproval submitter = ApprovalsUtil.newApproval(change.currentPatchSetId(), ctx.getUser(), LabelId.legacySubmit(), 1, ctx.getWhen());
update.putApproval(submitter.getLabel(), submitter.getValue());
ctx.getDb().patchSetApprovals().upsert(Collections.singleton(submitter));
return true;
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeData method reviewedBy.
public Set<Account.Id> reviewedBy() throws OrmException {
if (reviewedBy == null) {
if (!lazyLoad) {
return Collections.emptySet();
}
Change c = change();
if (c == null) {
return Collections.emptySet();
}
List<ReviewedByEvent> events = new ArrayList<>();
for (ChangeMessage msg : messages()) {
if (msg.getAuthor() != null) {
events.add(ReviewedByEvent.create(msg));
}
}
events = Lists.reverse(events);
reviewedBy = new LinkedHashSet<>();
Account.Id owner = c.getOwner();
for (ReviewedByEvent event : events) {
if (owner.equals(event.author())) {
break;
}
reviewedBy.add(event.author());
}
}
return reviewedBy;
}
Aggregations