Search in sources :

Example 1 with MergeOp

use of com.google.gerrit.server.git.MergeOp in project gerrit by GerritCodeReview.

the class PreviewSubmit method getBundles.

private BinaryResult getBundles(BatchUpdate.Factory updateFactory, RevisionResource rsrc, ArchiveFormat f) throws OrmException, RestApiException {
    ReviewDb db = dbProvider.get();
    ChangeControl control = rsrc.getControl();
    IdentifiedUser caller = control.getUser().asIdentifiedUser();
    Change change = rsrc.getChange();
    // Returned BinaryResult takes ownership and handles closing.
    @SuppressWarnings("resource") MergeOp op = mergeOpFactory.create(updateFactory);
    try {
        op.merge(db, change, caller, false, new SubmitInput(), true);
        BinaryResult bin = new SubmitPreviewResult(op, f, maxBundleSize);
        bin.disableGzip().setContentType(f.getMimeType()).setAttachmentName("submit-preview-" + change.getChangeId() + "." + format);
        return bin;
    } catch (OrmException | RestApiException | RuntimeException e) {
        op.close();
        throw e;
    }
}
Also used : MergeOp(com.google.gerrit.server.git.MergeOp) Change(com.google.gerrit.reviewdb.client.Change) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) OrmException(com.google.gwtorm.server.OrmException) ChangeControl(com.google.gerrit.server.project.ChangeControl) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult)

Example 2 with MergeOp

use of com.google.gerrit.server.git.MergeOp in project gerrit by GerritCodeReview.

the class Submit method mergeChange.

public Change mergeChange(BatchUpdate.Factory updateFactory, RevisionResource rsrc, IdentifiedUser submitter, SubmitInput input) throws OrmException, RestApiException, IOException {
    Change change = rsrc.getChange();
    if (!change.getStatus().isOpen()) {
        throw new ResourceConflictException("change is " + ChangeUtil.status(change));
    } else if (!ProjectUtil.branchExists(repoManager, change.getDest())) {
        throw new ResourceConflictException(String.format("destination branch \"%s\" not found.", change.getDest().get()));
    } else if (!rsrc.getPatchSet().getId().equals(change.currentPatchSetId())) {
        // TODO Allow submitting non-current revision by changing the current.
        throw new ResourceConflictException(String.format("revision %s is not current revision", rsrc.getPatchSet().getRevision().get()));
    }
    try (MergeOp op = mergeOpFactory.create(updateFactory)) {
        ReviewDb db = dbProvider.get();
        op.merge(db, change, submitter, true, input, false);
        try {
            change = changeNotesFactory.createChecked(db, change.getProject(), change.getId()).getChange();
        } catch (NoSuchChangeException e) {
            throw new ResourceConflictException("change is deleted");
        }
    }
    switch(change.getStatus()) {
        case MERGED:
            return change;
        case NEW:
            ChangeMessage msg = getConflictMessage(rsrc);
            if (msg != null) {
                throw new ResourceConflictException(msg.getMessage());
            }
        //$FALL-THROUGH$
        case ABANDONED:
        case DRAFT:
        default:
            throw new ResourceConflictException("change is " + ChangeUtil.status(change));
    }
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) MergeOp(com.google.gerrit.server.git.MergeOp) Change(com.google.gerrit.reviewdb.client.Change) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Aggregations

Change (com.google.gerrit.reviewdb.client.Change)2 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)2 MergeOp (com.google.gerrit.server.git.MergeOp)2 SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)1 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 ChangeControl (com.google.gerrit.server.project.ChangeControl)1 NoSuchChangeException (com.google.gerrit.server.project.NoSuchChangeException)1 OrmException (com.google.gwtorm.server.OrmException)1