Skip to content

Commit 78c69df

Browse files
augigmessner
authored andcommitted
Project archiving and unarchiving (#152)
* project archiving and unarchiving * expected response for archive and unarchive fixed * remove unnecessary preconditions for archiving test
1 parent 408e644 commit 78c69df

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/main/java/org/gitlab4j/api/ProjectApi.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,4 +1853,34 @@ public void unshareProject(Integer projectId, Integer groupId) throws GitLabApiE
18531853
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
18541854
delete(expectedStatus, null, "projects", projectId, "share", groupId);
18551855
}
1856+
1857+
/**
1858+
* Archive a project
1859+
*
1860+
* POST /projects/:id/archive
1861+
*
1862+
* @param projectId the ID of the project to archive, required
1863+
* @return the archived GitLab Project
1864+
* @throws GitLabApiException if any exception occurs
1865+
*/
1866+
public Project archiveProject(Integer projectId)
1867+
throws GitLabApiException {
1868+
Response response = post(Response.Status.CREATED, (new GitLabApiForm()), "projects", projectId, "archive");
1869+
return (response.readEntity(Project.class));
1870+
}
1871+
1872+
/**
1873+
* Unarchive a project
1874+
*
1875+
* POST /projects/:id/unarchive
1876+
*
1877+
* @param projectId the ID of the project to unarchive, required
1878+
* @return the unarchived GitLab Project
1879+
* @throws GitLabApiException if any exception occurs
1880+
*/
1881+
public Project unarchiveProject(Integer projectId)
1882+
throws GitLabApiException {
1883+
Response response = post(Response.Status.CREATED, (new GitLabApiForm()), "projects", projectId, "unarchive");
1884+
return (response.readEntity(Project.class));
1885+
}
18561886
}

src/test/java/org/gitlab4j/api/TestProjectApi.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,15 @@ public void testShareProject() throws GitLabApiException {
440440
gitLabApi.getProjectApi().unshareProject(project.getId(), shareGroup.getId());
441441
}
442442

443+
@Test
444+
public void testArchiveProject() throws GitLabApiException {
445+
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
446+
assertNotNull(project);
447+
448+
assertEquals(true, gitLabApi.getProjectApi().archiveProject(project.getId()).getArchived());
449+
assertEquals(false, gitLabApi.getProjectApi().unarchiveProject(project.getId()).getArchived());
450+
}
451+
443452
@Test
444453
public void testGetOptionalProject() throws GitLabApiException {
445454

0 commit comments

Comments
 (0)