Search in sources :

Example 1 with PatchSetInfoNotAvailableException

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);
}
Also used : ChangeContext(com.google.gerrit.server.update.ChangeContext) PatchSetInfoNotAvailableException(com.google.gerrit.server.patch.PatchSetInfoNotAvailableException) 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) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with PatchSetInfoNotAvailableException

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);
        }
    }
}
Also used : EmailException(com.google.gerrit.exceptions.EmailException) PatchSetInfoNotAvailableException(com.google.gerrit.server.patch.PatchSetInfoNotAvailableException) StorageException(com.google.gerrit.exceptions.StorageException)

Aggregations

PatchSetInfoNotAvailableException (com.google.gerrit.server.patch.PatchSetInfoNotAvailableException)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 EmailException (com.google.gerrit.exceptions.EmailException)1 StorageException (com.google.gerrit.exceptions.StorageException)1 Change (com.google.gerrit.reviewdb.client.Change)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)1 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)1 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)1 ChangeContext (com.google.gerrit.server.update.ChangeContext)1 Test (org.junit.Test)1