DeleteBranches: Split static Input class out to extension API
Change-Id: I359b6a7827d81c3a87900a5d6680d1df5d4e9ba6
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2016 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.extensions.api.projects;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeleteBranchesInput {
|
||||||
|
public List<String> branches;
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import static java.lang.String.format;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.common.ChangeHooks;
|
import com.google.gerrit.common.ChangeHooks;
|
||||||
|
import com.google.gerrit.extensions.api.projects.DeleteBranchesInput;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.Response;
|
import com.google.gerrit.extensions.restapi.Response;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
@@ -25,7 +26,6 @@ import com.google.gerrit.reviewdb.client.Branch;
|
|||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.project.DeleteBranches.Input;
|
|
||||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -44,26 +44,11 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class DeleteBranches implements RestModifyView<ProjectResource, Input> {
|
class DeleteBranches implements RestModifyView<ProjectResource, DeleteBranchesInput> {
|
||||||
private static final Logger log = LoggerFactory.getLogger(DeleteBranches.class);
|
private static final Logger log = LoggerFactory.getLogger(DeleteBranches.class);
|
||||||
|
|
||||||
static class Input {
|
|
||||||
List<String> branches;
|
|
||||||
|
|
||||||
static Input init(Input in) {
|
|
||||||
if (in == null) {
|
|
||||||
in = new Input();
|
|
||||||
}
|
|
||||||
if (in.branches == null) {
|
|
||||||
in.branches = Lists.newArrayListWithCapacity(1);
|
|
||||||
}
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Provider<IdentifiedUser> identifiedUser;
|
private final Provider<IdentifiedUser> identifiedUser;
|
||||||
private final GitRepositoryManager repoManager;
|
private final GitRepositoryManager repoManager;
|
||||||
private final Provider<InternalChangeQuery> queryProvider;
|
private final Provider<InternalChangeQuery> queryProvider;
|
||||||
@@ -84,9 +69,16 @@ class DeleteBranches implements RestModifyView<ProjectResource, Input> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<?> apply(ProjectResource project, Input input)
|
public Response<?> apply(ProjectResource project, DeleteBranchesInput input)
|
||||||
throws OrmException, IOException, ResourceConflictException {
|
throws OrmException, IOException, ResourceConflictException {
|
||||||
input = Input.init(input);
|
|
||||||
|
if (input == null) {
|
||||||
|
input = new DeleteBranchesInput();
|
||||||
|
}
|
||||||
|
if (input.branches == null) {
|
||||||
|
input.branches = Lists.newArrayListWithCapacity(1);
|
||||||
|
}
|
||||||
|
|
||||||
try (Repository r = repoManager.openRepository(project.getNameKey())) {
|
try (Repository r = repoManager.openRepository(project.getNameKey())) {
|
||||||
BatchRefUpdate batchUpdate = r.getRefDatabase().newBatchUpdate();
|
BatchRefUpdate batchUpdate = r.getRefDatabase().newBatchUpdate();
|
||||||
for (String branch : input.branches) {
|
for (String branch : input.branches) {
|
||||||
|
|||||||
Reference in New Issue
Block a user