Commit 463c6e96 authored by Greg Messner's avatar Greg Messner
Browse files

forkProject() methods now return the newly forked Project instance (#106).

parent b863c786
...@@ -841,10 +841,11 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -841,10 +841,11 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param namespace path of the namespace that the project will be forked to * @param namespace path of the namespace that the project will be forked to
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void forkProject(Integer id, String namespace) throws GitLabApiException { public Project forkProject(Integer id, String namespace) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("namespace", namespace, true); GitLabApiForm formData = new GitLabApiForm().withParam("namespace", namespace, true);
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.CREATED);
post(expectedStatus, formData, "projects", id, "fork"); Response response = post(expectedStatus, formData, "projects", id, "fork");
return (response.readEntity(Project.class));
} }
/** /**
...@@ -858,8 +859,8 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -858,8 +859,8 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param namespace path of the namespace that the project will be forked to * @param namespace path of the namespace that the project will be forked to
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void forkProject(Project project, String namespace) throws GitLabApiException { public Project forkProject(Project project, String namespace) throws GitLabApiException {
forkProject(project.getId(), namespace); return (forkProject(project.getId(), namespace));
} }
/** /**
...@@ -873,10 +874,11 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -873,10 +874,11 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param namespaceId ID of the namespace that the project will be forked to * @param namespaceId ID of the namespace that the project will be forked to
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void forkProject(Integer id, Integer namespaceId) throws GitLabApiException { public Project forkProject(Integer id, Integer namespaceId) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("namespace", namespaceId, true); GitLabApiForm formData = new GitLabApiForm().withParam("namespace", namespaceId, true);
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.CREATED);
post(expectedStatus, formData, "projects", id, "fork"); Response response = post(expectedStatus, formData, "projects", id, "fork");
return (response.readEntity(Project.class));
} }
/** /**
...@@ -890,8 +892,8 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -890,8 +892,8 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param namespaceId ID of the namespace that the project will be forked to * @param namespaceId ID of the namespace that the project will be forked to
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void forkProject(Project project, Integer namespaceId) throws GitLabApiException { public Project forkProject(Project project, Integer namespaceId) throws GitLabApiException {
forkProject(project.getId(), namespaceId); return (forkProject(project.getId(), namespaceId));
} }
/** /**
......
...@@ -47,6 +47,7 @@ import org.junit.runners.MethodSorters; ...@@ -47,6 +47,7 @@ import org.junit.runners.MethodSorters;
* TEST_PROJECT_NAME * TEST_PROJECT_NAME
* TEST_HOST_URL * TEST_HOST_URL
* TEST_PRIVATE_TOKEN * TEST_PRIVATE_TOKEN
* TEST_GROUP_PROJECT
* *
* If any of the above are NULL, all tests in this class will be skipped. * If any of the above are NULL, all tests in this class will be skipped.
* *
...@@ -60,12 +61,16 @@ public class TestProjectApi { ...@@ -60,12 +61,16 @@ public class TestProjectApi {
private static final String TEST_PROJECT_NAME; private static final String TEST_PROJECT_NAME;
private static final String TEST_HOST_URL; private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN; private static final String TEST_PRIVATE_TOKEN;
private static final String TEST_GROUP;
private static final String TEST_GROUP_PROJECT;
static { static {
TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE"); TEST_NAMESPACE = TestUtils.getProperty("TEST_NAMESPACE");
TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME"); TEST_PROJECT_NAME = TestUtils.getProperty("TEST_PROJECT_NAME");
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
TEST_GROUP = TestUtils.getProperty("TEST_GROUP");
TEST_GROUP_PROJECT = TestUtils.getProperty("TEST_GROUP_PROJECT");
} }
private static final String TEST_PROJECT_NAME_1 = "test-gitlab4j-create-project"; private static final String TEST_PROJECT_NAME_1 = "test-gitlab4j-create-project";
...@@ -123,6 +128,14 @@ public class TestProjectApi { ...@@ -123,6 +128,14 @@ public class TestProjectApi {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_UPDATE); Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME_UPDATE);
gitLabApi.getProjectApi().deleteProject(project); gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {} } catch (GitLabApiException ignore) {}
if (TEST_GROUP != null && TEST_GROUP_PROJECT != null) {
try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_GROUP_PROJECT);
gitLabApi.getProjectApi().deleteProject(project);
} catch (GitLabApiException ignore) {
}
}
} }
} }
...@@ -382,4 +395,16 @@ public class TestProjectApi { ...@@ -382,4 +395,16 @@ public class TestProjectApi {
assertTrue(projects != null); assertTrue(projects != null);
assertTrue(projects.size() > 0); assertTrue(projects.size() > 0);
} }
@Test
public void testForkProject() throws GitLabApiException {
assumeTrue(TEST_GROUP != null && TEST_GROUP_PROJECT != null);
assumeTrue(TEST_GROUP.trim().length() > 0 && TEST_GROUP_PROJECT.trim().length() > 0);
Project project = gitLabApi.getProjectApi().getProject(TEST_GROUP, TEST_GROUP_PROJECT);
assertNotNull(project);
Project forkedProject = gitLabApi.getProjectApi().forkProject(project.getId(), TEST_NAMESPACE);
assertNotNull(forkedProject);
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment