Plugin API: Add get project API
Change-Id: Iff3ddf558a1526cfa7324175767ec7e7bc0f7803
This commit is contained in:
parent
8f3931bb0d
commit
cddaea317a
@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.acceptance.api.project;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||
@ -30,17 +32,21 @@ public class ProjectIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
public void createProjectFoo() throws RestApiException {
|
||||
gApi.projects()
|
||||
.name("foo")
|
||||
.create();
|
||||
String name = "foo";
|
||||
assertEquals(name,
|
||||
gApi.projects()
|
||||
.name(name)
|
||||
.create()
|
||||
.get()
|
||||
.name);
|
||||
}
|
||||
|
||||
@Test(expected = RestApiException.class)
|
||||
public void createProjectFooBar() throws RestApiException {
|
||||
ProjectInput in = new ProjectInput();
|
||||
in.name = "bar";
|
||||
in.name = "foo";
|
||||
gApi.projects()
|
||||
.name("foo")
|
||||
.name("bar")
|
||||
.create(in);
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,13 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectApi;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||
import com.google.gerrit.extensions.common.InheritableBoolean;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.common.SubmitType;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
@ -65,6 +68,21 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
@Inject
|
||||
private GitRepositoryManager git;
|
||||
|
||||
@Inject
|
||||
private GerritApi gApi;
|
||||
|
||||
@Test
|
||||
public void testCreateProjectApi() throws RestApiException, IOException {
|
||||
final String newProjectName = "newProject";
|
||||
ProjectApi projectApi = gApi.projects().name(newProjectName).create();
|
||||
ProjectInfo p = projectApi.get();
|
||||
assertEquals(newProjectName, p.name);
|
||||
ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
|
||||
assertNotNull(projectState);
|
||||
assertProjectInfo(projectState.getProject(), p);
|
||||
assertHead(newProjectName, "refs/heads/master");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateProject() throws IOException {
|
||||
final String newProjectName = "newProject";
|
||||
|
@ -14,10 +14,12 @@
|
||||
|
||||
package com.google.gerrit.extensions.api.projects;
|
||||
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
|
||||
public interface ProjectApi {
|
||||
ProjectApi create() throws RestApiException;
|
||||
ProjectApi create(ProjectInput in) throws RestApiException;
|
||||
ProjectInfo get();
|
||||
BranchApi branch(String ref);
|
||||
}
|
||||
|
@ -14,10 +14,12 @@
|
||||
|
||||
package com.google.gerrit.server.api.projects;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gerrit.common.errors.ProjectCreationFailedException;
|
||||
import com.google.gerrit.extensions.api.projects.BranchApi;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectApi;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
@ -25,6 +27,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.server.project.CreateProject;
|
||||
import com.google.gerrit.server.project.ProjectJson;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.gerrit.server.project.ProjectsCollection;
|
||||
import com.google.inject.Provider;
|
||||
@ -43,6 +46,7 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
private final ProjectApiImpl.Factory projectApi;
|
||||
private final ProjectsCollection projects;
|
||||
private final ProjectResource project;
|
||||
private final ProjectJson projectJson;
|
||||
private final String name;
|
||||
private final BranchApiImpl.Factory branchApi;
|
||||
|
||||
@ -50,31 +54,35 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
ProjectApiImpl(Provider<CreateProject.Factory> createProjectFactory,
|
||||
ProjectApiImpl.Factory projectApi,
|
||||
ProjectsCollection projects,
|
||||
ProjectJson projectJson,
|
||||
BranchApiImpl.Factory branchApiFactory,
|
||||
@Assisted ProjectResource project) {
|
||||
this(createProjectFactory, projectApi, projects, branchApiFactory, project,
|
||||
null);
|
||||
this(createProjectFactory, projectApi, projects, projectJson,
|
||||
branchApiFactory, project, null);
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
ProjectApiImpl(Provider<CreateProject.Factory> createProjectFactory,
|
||||
ProjectApiImpl.Factory projectApi,
|
||||
ProjectsCollection projects,
|
||||
ProjectJson projectJson,
|
||||
BranchApiImpl.Factory branchApiFactory,
|
||||
@Assisted String name) {
|
||||
this(createProjectFactory, projectApi, projects, branchApiFactory, null,
|
||||
name);
|
||||
this(createProjectFactory, projectApi, projects, projectJson,
|
||||
branchApiFactory, null, name);
|
||||
}
|
||||
|
||||
private ProjectApiImpl(Provider<CreateProject.Factory> createProjectFactory,
|
||||
ProjectApiImpl.Factory projectApi,
|
||||
ProjectsCollection projects,
|
||||
ProjectJson projectJson,
|
||||
BranchApiImpl.Factory branchApiFactory,
|
||||
ProjectResource project,
|
||||
String name) {
|
||||
this.createProjectFactory = createProjectFactory;
|
||||
this.projectApi = projectApi;
|
||||
this.projects = projects;
|
||||
this.projectJson = projectJson;
|
||||
this.project = project;
|
||||
this.name = name;
|
||||
this.branchApi = branchApiFactory;
|
||||
@ -101,6 +109,12 @@ public class ProjectApiImpl implements ProjectApi {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectInfo get() {
|
||||
Preconditions.checkNotNull(project);
|
||||
return projectJson.format(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchApi branch(String ref) {
|
||||
return branchApi.create(project, ref);
|
||||
|
Loading…
x
Reference in New Issue
Block a user