use of com.google.gerrit.server.patch.PatchSetInfoNotAvailableException in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method highestNumberedPatchSetIsNotCurrent.
@Test
public void highestNumberedPatchSetIsNotCurrent() throws Exception {
PushOneCommit.Result r1 = createChange();
PatchSet.Id psId1 = r1.getPatchSetId();
Change.Id id = psId1.getParentKey();
PushOneCommit.Result r2 = amendChange(r1.getChangeId());
PatchSet.Id psId2 = r2.getPatchSetId();
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 PatchSetInfoNotAvailableException {
ctx.getChange().setCurrentPatchSet(patchSetInfoFactory.get(ctx.getDb(), ctx.getNotes(), psId1));
return true;
}
});
bu.execute();
}
ChangeNotes notes = notesFactory.create(db, project, id);
assertThat(psUtil.byChangeAsMap(db, notes).keySet()).containsExactly(psId1, psId2);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId1);
assertThat(db.changes().get(id).currentPatchSetId()).isEqualTo(psId1);
checker.rebuildAndCheckChanges(id);
setNotesMigration(true, true);
notes = notesFactory.create(db, project, id);
assertThat(psUtil.byChangeAsMap(db, notes).keySet()).containsExactly(psId1, psId2);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId1);
}
use of com.google.gerrit.server.patch.PatchSetInfoNotAvailableException in project gerrit by GerritCodeReview.
the class ChangeEmail method init.
/**
* Setup the message headers and envelope (TO, CC, BCC).
*/
@Override
protected void init() throws EmailException {
if (args.projectCache != null) {
projectState = args.projectCache.get(change.getProject()).orElse(null);
} else {
projectState = null;
}
if (patchSet == null) {
try {
patchSet = changeData.currentPatchSet();
} catch (StorageException err) {
patchSet = null;
}
}
if (patchSet != null) {
setHeader(MailHeader.PATCH_SET.fieldName(), patchSet.number() + "");
if (patchSetInfo == null) {
try {
patchSetInfo = args.patchSetInfoFactory.get(changeData.notes(), patchSet.id());
} catch (PatchSetInfoNotAvailableException | StorageException err) {
patchSetInfo = null;
}
}
}
authors = getAuthors();
try {
stars = changeData.stars();
} catch (StorageException e) {
throw new EmailException("Failed to load stars for change " + change.getChangeId(), e);
}
super.init();
if (timestamp != null) {
setHeader(FieldName.DATE, timestamp);
}
setChangeSubjectHeader();
setHeader(MailHeader.CHANGE_ID.fieldName(), "" + change.getKey().get());
setHeader(MailHeader.CHANGE_NUMBER.fieldName(), "" + change.getChangeId());
setHeader(MailHeader.PROJECT.fieldName(), "" + change.getProject());
setChangeUrlHeader();
setCommitIdHeader();
if (notify.handling().compareTo(NotifyHandling.OWNER_REVIEWERS) >= 0) {
try {
addByEmail(RecipientType.CC, changeData.reviewersByEmail().byState(ReviewerStateInternal.CC));
addByEmail(RecipientType.CC, changeData.reviewersByEmail().byState(ReviewerStateInternal.REVIEWER));
} catch (StorageException e) {
throw new EmailException("Failed to add unregistered CCs " + change.getChangeId(), e);
}
}
}
Aggregations