use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOf.
@Test
public void voteOnBehalfOf() throws Exception {
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
ReviewInput in = ReviewInput.recommend();
in.onBehalfOf = user.id.toString();
in.message = "Message on behalf of";
revision.review(in);
PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
assertThat(psa.getPatchSetId().get()).isEqualTo(1);
assertThat(psa.getLabel()).isEqualTo("Code-Review");
assertThat(psa.getAccountId()).isEqualTo(user.id);
assertThat(psa.getValue()).isEqualTo(1);
assertThat(psa.getRealAccountId()).isEqualTo(admin.id);
ChangeData cd = r.getChange();
ChangeMessage m = Iterables.getLast(cmUtil.byChange(db, cd.notes()));
assertThat(m.getMessage()).endsWith(in.message);
assertThat(m.getAuthor()).isEqualTo(user.id);
assertThat(m.getRealAuthor()).isEqualTo(admin.id);
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeNotesParser method updatePatchSetStates.
private void updatePatchSetStates() {
Set<PatchSet.Id> missing = new TreeSet<>(ReviewDbUtil.intKeyOrdering());
for (Iterator<PatchSet> it = patchSets.values().iterator(); it.hasNext(); ) {
PatchSet ps = it.next();
if (ps.getRevision().equals(PARTIAL_PATCH_SET)) {
missing.add(ps.getId());
it.remove();
}
}
for (Map.Entry<PatchSet.Id, PatchSetState> e : patchSetStates.entrySet()) {
switch(e.getValue()) {
case PUBLISHED:
default:
break;
case DELETED:
patchSets.remove(e.getKey());
break;
case DRAFT:
PatchSet ps = patchSets.get(e.getKey());
if (ps != null) {
ps.setDraft(true);
}
break;
}
}
// Post-process other collections to remove items corresponding to deleted
// (or otherwise missing) patch sets. This is safer than trying to prevent
// insertion, as it will also filter out items racily added after the patch
// set was deleted.
changeMessagesByPatchSet.keys().retainAll(patchSets.keySet());
int pruned = pruneEntitiesForMissingPatchSets(allChangeMessages, ChangeMessage::getPatchSetId, missing);
pruned += pruneEntitiesForMissingPatchSets(comments.values(), c -> new PatchSet.Id(id, c.key.patchSetId), missing);
pruned += pruneEntitiesForMissingPatchSets(approvals.values(), PatchSetApproval::getPatchSetId, missing);
if (!missing.isEmpty()) {
log.warn("ignoring {} additional entities due to missing patch sets: {}", pruned, missing);
}
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeBundle method diffChangeMessages.
private static void diffChangeMessages(List<String> diffs, ChangeBundle bundleA, ChangeBundle bundleB) {
if (bundleA.source == REVIEW_DB && bundleB.source == REVIEW_DB) {
// Both came from ReviewDb: check all fields exactly.
Map<ChangeMessage.Key, ChangeMessage> as = changeMessageMap(bundleA.filterChangeMessages());
Map<ChangeMessage.Key, ChangeMessage> bs = changeMessageMap(bundleB.filterChangeMessages());
for (ChangeMessage.Key k : diffKeySets(diffs, as, bs)) {
ChangeMessage a = as.get(k);
ChangeMessage b = bs.get(k);
String desc = describe(k);
diffColumns(diffs, ChangeMessage.class, desc, bundleA, a, bundleB, b);
}
return;
}
Change.Id id = bundleA.getChange().getId();
checkArgument(id.equals(bundleB.getChange().getId()));
// Try to pair up matching ChangeMessages from each side, and succeed only
// if both collections are empty at the end. Quadratic in the worst case,
// but easy to reason about.
List<ChangeMessage> as = new LinkedList<>(bundleA.filterChangeMessages());
ListMultimap<ChangeMessageCandidate, ChangeMessage> bs = LinkedListMultimap.create();
for (ChangeMessage b : bundleB.filterChangeMessages()) {
bs.put(ChangeMessageCandidate.create(b), b);
}
Iterator<ChangeMessage> ait = as.iterator();
A: while (ait.hasNext()) {
ChangeMessage a = ait.next();
Iterator<ChangeMessage> bit = bs.get(ChangeMessageCandidate.create(a)).iterator();
while (bit.hasNext()) {
ChangeMessage b = bit.next();
if (changeMessagesMatch(bundleA, a, bundleB, b)) {
ait.remove();
bit.remove();
continue A;
}
}
}
if (as.isEmpty() && bs.isEmpty()) {
return;
}
StringBuilder sb = new StringBuilder("ChangeMessages differ for Change.Id ").append(id).append('\n');
if (!as.isEmpty()) {
sb.append("Only in A:");
for (ChangeMessage cm : as) {
sb.append("\n ").append(cm);
}
if (!bs.isEmpty()) {
sb.append('\n');
}
}
if (!bs.isEmpty()) {
sb.append("Only in B:");
for (ChangeMessage cm : CHANGE_MESSAGE_ORDER.sortedCopy(bs.values())) {
sb.append("\n ").append(cm);
}
}
diffs.add(sb.toString());
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffChangeMessagesMixedSourcesWithDifferences.
@Test
public void diffChangeMessagesMixedSourcesWithDifferences() throws Exception {
Change c = TestChanges.newChange(project, accountId);
int id = c.getId().get();
ChangeMessage cm1 = new ChangeMessage(new ChangeMessage.Key(c.getId(), "uuid1"), accountId, TimeUtil.nowTs(), c.currentPatchSetId());
cm1.setMessage("message 1");
ChangeMessage cm2 = clone(cm1);
cm2.setMessage("message 2");
ChangeMessage cm3 = clone(cm1);
// Differs only in UUID.
cm3.getKey().set("uuid2");
ChangeBundle b1 = new ChangeBundle(c, messages(cm1, cm3), latest(c), approvals(), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c, messages(cm2, cm3), latest(c), approvals(), comments(), reviewers(), NOTE_DB);
// Implementation happens to pair up cm1 in b1 with cm3 in b2 because it
// depends on iteration order and doesn't care about UUIDs. The important
// thing is that there's some diff.
assertDiffs(b1, b2, "ChangeMessages differ for Change.Id " + id + "\n" + "Only in A:\n " + cm3 + "\n" + "Only in B:\n " + cm2);
assertDiffs(b2, b1, "ChangeMessages differ for Change.Id " + id + "\n" + "Only in A:\n " + cm2 + "\n" + "Only in B:\n " + cm3);
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffChangeMessageKeySets.
@Test
public void diffChangeMessageKeySets() throws Exception {
Change c = TestChanges.newChange(project, accountId);
int id = c.getId().get();
ChangeMessage cm1 = new ChangeMessage(new ChangeMessage.Key(c.getId(), "uuid1"), accountId, TimeUtil.nowTs(), c.currentPatchSetId());
ChangeMessage cm2 = new ChangeMessage(new ChangeMessage.Key(c.getId(), "uuid2"), accountId, TimeUtil.nowTs(), c.currentPatchSetId());
ChangeBundle b1 = new ChangeBundle(c, messages(cm1), latest(c), approvals(), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c, messages(cm2), latest(c), approvals(), comments(), reviewers(), REVIEW_DB);
assertDiffs(b1, b2, "ChangeMessage.Key sets differ:" + " [" + id + ",uuid1] only in A; [" + id + ",uuid2] only in B");
}
Aggregations