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()));
}
}
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);
}
}
}
Aggregations