Commit a5ec26fb authored by Greg Messner's avatar Greg Messner
Browse files

Added starProject() and unstarProject() (#194).

parent 8a456a46
...@@ -2097,4 +2097,34 @@ public class ProjectApi extends AbstractApi implements Constants { ...@@ -2097,4 +2097,34 @@ public class ProjectApi extends AbstractApi implements Constants {
public Pager<Project> getForks(Integer projectId, int itemsPerPage) throws GitLabApiException { public Pager<Project> getForks(Integer projectId, int itemsPerPage) throws GitLabApiException {
return new Pager<Project>(this, Project.class, itemsPerPage, null, "projects", projectId, "forks"); return new Pager<Project>(this, Project.class, itemsPerPage, null, "projects", projectId, "forks");
} }
/**
* Star a project.
*
* POST /projects/:id/star
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @return a Project instance with the new project info
* @throws GitLabApiException if any exception occurs
*/
public Project starProject(Object projectIdOrPath) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.CREATED);
Response response = post(expectedStatus, (Form) null, "projects", getProjectIdOrPath(projectIdOrPath), "star");
return (response.readEntity(Project.class));
}
/**
* Unstar a project.
*
* POST /projects/:id/unstar
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @return a Project instance with the new project info
* @throws GitLabApiException if any exception occurs
*/
public Project unstarProject(Object projectIdOrPath) throws GitLabApiException {
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.CREATED);
Response response = post(expectedStatus, (Form) null, "projects", getProjectIdOrPath(projectIdOrPath), "unstar");
return (response.readEntity(Project.class));
}
} }
\ No newline at end of file
...@@ -495,4 +495,24 @@ public class TestProjectApi { ...@@ -495,4 +495,24 @@ public class TestProjectApi {
assertFalse(optional.isPresent()); assertFalse(optional.isPresent());
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), GitLabApi.getOptionalException(optional).getHttpStatus()); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), GitLabApi.getOptionalException(optional).getHttpStatus());
} }
@Test
public void testStarAndUnstarProject() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
assertNotNull(project);
try {
gitLabApi.getProjectApi().unstarProject(project);
} catch (Exception ignore) {
}
Project starredProject = gitLabApi.getProjectApi().starProject(project);
assertNotNull(starredProject);
assertEquals(1, (int)starredProject.getStarCount());
Project unstarredProject = gitLabApi.getProjectApi().unstarProject(project);
assertNotNull(unstarredProject);
assertEquals(0, (int)unstarredProject.getStarCount());
}
} }
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