Search in sources :

Example 1 with MergeOp

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

the class Submit method mergeChange.

@UsedAt(UsedAt.Project.GOOGLE)
public Change mergeChange(RevisionResource rsrc, IdentifiedUser submitter, SubmitInput input) throws RestApiException, IOException, UpdateException, ConfigInvalidException, PermissionBackendException {
    Change change = rsrc.getChange();
    if (!change.isNew()) {
        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().branch()));
    } else if (!rsrc.getPatchSet().id().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().commitId().name()));
    }
    try (MergeOp op = mergeOpProvider.get()) {
        Change updatedChange;
        updatedChange = op.merge(change, submitter, true, input, false);
        if (updatedChange.isMerged()) {
            return updatedChange;
        }
        throw new IllegalStateException(String.format("change %s of project %s unexpectedly had status %s after submit attempt", updatedChange.getId(), updatedChange.getProject(), updatedChange.getStatus()));
    }
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) MergeOp(com.google.gerrit.server.submit.MergeOp) Change(com.google.gerrit.entities.Change) UsedAt(com.google.gerrit.common.UsedAt)

Example 2 with MergeOp

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

the class ReceiveCommits method submit.

private void submit(Collection<CreateRequest> create, Collection<ReplaceRequest> replace) throws RestApiException, UpdateException, IOException, ConfigInvalidException, PermissionBackendException {
    try (TraceTimer traceTimer = newTimer("submit")) {
        Map<ObjectId, Change> bySha = Maps.newHashMapWithExpectedSize(create.size() + replace.size());
        for (CreateRequest r : create) {
            requireNonNull(r.change, () -> String.format("cannot submit new change %s; op may not have run", r.changeId));
            bySha.put(r.commit, r.change);
        }
        for (ReplaceRequest r : replace) {
            bySha.put(r.newCommitId, r.notes.getChange());
        }
        Change tipChange = bySha.get(magicBranch.cmd.getNewId());
        requireNonNull(tipChange, () -> String.format("tip of push does not correspond to a change; found these changes: %s", bySha));
        logger.atFine().log("Processing submit with tip change %s (%s)", tipChange.getId(), magicBranch.cmd.getNewId());
        try (MergeOp op = mergeOpProvider.get()) {
            SubmitInput submitInput = new SubmitInput();
            submitInput.notify = magicBranch.notifyHandling;
            submitInput.notifyDetails = new HashMap<>();
            submitInput.notifyDetails.put(RecipientType.TO, new NotifyInfo(magicBranch.notifyTo.stream().map(Object::toString).collect(toList())));
            submitInput.notifyDetails.put(RecipientType.CC, new NotifyInfo(magicBranch.notifyCc.stream().map(Object::toString).collect(toList())));
            submitInput.notifyDetails.put(RecipientType.BCC, new NotifyInfo(magicBranch.notifyBcc.stream().map(Object::toString).collect(toList())));
            op.merge(tipChange, user, false, submitInput, false);
        }
    }
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) ObjectId(org.eclipse.jgit.lib.ObjectId) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) MergeOp(com.google.gerrit.server.submit.MergeOp) NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) Change(com.google.gerrit.entities.Change)

Aggregations

Change (com.google.gerrit.entities.Change)2 MergeOp (com.google.gerrit.server.submit.MergeOp)2 UsedAt (com.google.gerrit.common.UsedAt)1 NotifyInfo (com.google.gerrit.extensions.api.changes.NotifyInfo)1 SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1