CreateBranch: Use extension API's BranchInput instead of static inner class
Change-Id: I9844de5f57283d326288f931f24d98faf1a7481e
This commit is contained in:
@@ -19,4 +19,5 @@ import com.google.gerrit.extensions.restapi.DefaultInput;
|
|||||||
public class BranchInput {
|
public class BranchInput {
|
||||||
@DefaultInput
|
@DefaultInput
|
||||||
public String revision;
|
public String revision;
|
||||||
|
public String ref;
|
||||||
}
|
}
|
||||||
|
@@ -65,11 +65,8 @@ public class BranchApiImpl implements BranchApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BranchApi create(BranchInput in) throws RestApiException {
|
public BranchApi create(BranchInput input) throws RestApiException {
|
||||||
try {
|
try {
|
||||||
CreateBranch.Input input = new CreateBranch.Input();
|
|
||||||
input.ref = ref;
|
|
||||||
input.revision = in.revision;
|
|
||||||
createBranchFactory.create(ref).apply(project, input);
|
createBranchFactory.create(ref).apply(project, input);
|
||||||
return this;
|
return this;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@@ -17,9 +17,9 @@ package com.google.gerrit.server.project;
|
|||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.common.ChangeHooks;
|
import com.google.gerrit.common.ChangeHooks;
|
||||||
import com.google.gerrit.extensions.api.projects.BranchInfo;
|
import com.google.gerrit.extensions.api.projects.BranchInfo;
|
||||||
|
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
@@ -29,7 +29,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
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.CreateBranch.Input;
|
|
||||||
import com.google.gerrit.server.util.MagicBranch;
|
import com.google.gerrit.server.util.MagicBranch;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
@@ -54,16 +53,9 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class CreateBranch implements RestModifyView<ProjectResource, Input> {
|
public class CreateBranch implements RestModifyView<ProjectResource, BranchInput> {
|
||||||
private static final Logger log = LoggerFactory.getLogger(CreateBranch.class);
|
private static final Logger log = LoggerFactory.getLogger(CreateBranch.class);
|
||||||
|
|
||||||
public static class Input {
|
|
||||||
public String ref;
|
|
||||||
|
|
||||||
@DefaultInput
|
|
||||||
public String revision;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Factory {
|
public interface Factory {
|
||||||
CreateBranch create(String ref);
|
CreateBranch create(String ref);
|
||||||
}
|
}
|
||||||
@@ -90,11 +82,11 @@ public class CreateBranch implements RestModifyView<ProjectResource, Input> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BranchInfo apply(ProjectResource rsrc, Input input)
|
public BranchInfo apply(ProjectResource rsrc, BranchInput input)
|
||||||
throws BadRequestException, AuthException, ResourceConflictException,
|
throws BadRequestException, AuthException, ResourceConflictException,
|
||||||
IOException {
|
IOException {
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
input = new Input();
|
input = new BranchInput();
|
||||||
}
|
}
|
||||||
if (input.ref != null && !ref.equals(input.ref)) {
|
if (input.ref != null && !ref.equals(input.ref)) {
|
||||||
throw new BadRequestException("ref must match URL");
|
throw new BadRequestException("ref must match URL");
|
||||||
|
@@ -14,16 +14,16 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.project;
|
package com.google.gerrit.server.project;
|
||||||
|
|
||||||
|
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
import com.google.gerrit.server.project.CreateBranch.Input;
|
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class PutBranch implements RestModifyView<BranchResource, Input> {
|
public class PutBranch implements RestModifyView<BranchResource, BranchInput> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object apply(BranchResource rsrc, Input input)
|
public Object apply(BranchResource rsrc, BranchInput input)
|
||||||
throws ResourceConflictException {
|
throws ResourceConflictException {
|
||||||
throw new ResourceConflictException("Branch \"" + rsrc.getBranchInfo().ref
|
throw new ResourceConflictException("Branch \"" + rsrc.getBranchInfo().ref
|
||||||
+ "\" already exists");
|
+ "\" already exists");
|
||||||
|
Reference in New Issue
Block a user