Add changes/<id>/submitted_together REST API call
This REST API call will answer the set of changes which will be affected by submitting the given change. The options set are the same as were used for the the 'same topic' tab, such that this call can be used to service that tab eventually. Change-Id: Ie1a3a72db132b3fda63f2602213269641c8d943f
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// Copyright (C) 2015 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.extensions.client.ListChangesOption;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.git.ChangeSet;
|
||||
import com.google.gerrit.server.git.MergeSuperSet;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class SubmittedTogether implements RestReadView<ChangeResource> {
|
||||
private static final Logger log = LoggerFactory.getLogger(
|
||||
SubmittedTogether.class);
|
||||
|
||||
private final ChangeJson json;
|
||||
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final MergeSuperSet mergeSuperSet;
|
||||
|
||||
@Inject
|
||||
SubmittedTogether(ChangeJson json,
|
||||
Provider<ReviewDb> dbProvider,
|
||||
MergeSuperSet mergeSuperSet) {
|
||||
this.json = json;
|
||||
this.dbProvider = dbProvider;
|
||||
this.mergeSuperSet = mergeSuperSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChangeInfo> apply(ChangeResource resource)
|
||||
throws AuthException, BadRequestException,
|
||||
ResourceConflictException, Exception {
|
||||
try {
|
||||
ChangeSet cs = mergeSuperSet.completeChangeSet(dbProvider.get(),
|
||||
ChangeSet.create(resource.getChange()));
|
||||
json.addOptions(EnumSet.of(
|
||||
ListChangesOption.CURRENT_REVISION,
|
||||
ListChangesOption.CURRENT_COMMIT,
|
||||
ListChangesOption.DETAILED_LABELS,
|
||||
ListChangesOption.LABELS));
|
||||
return json.format(cs.ids());
|
||||
} catch (OrmException | IOException e) {
|
||||
log.error("Error on getting a ChangeSet", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user