Skip to content

Commit

Permalink
Add method to retrieve projects that the user is member of (timols#243)
Browse files Browse the repository at this point in the history
* Add method to retrieve projects that the user is member of

* Fix methods to retrieve starred and owned projects

In these two methods the API URL was being created with two query
objects, which renders an invalid URL
  • Loading branch information
miguelaferreira authored and timols committed Sep 15, 2017
1 parent e650ce4 commit 14e4766
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/org/gitlab/api/GitlabAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,22 @@ public List<GitlabProject> getProjects() throws IOException {
*/
public List<GitlabProject> getOwnedProjects() throws IOException {
Query query = new Query().append("owner", "true");
String tailUrl = GitlabProject.URL + query.toString() + PARAM_MAX_ITEMS_PER_PAGE;
query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
String tailUrl = GitlabProject.URL + query.toString();
return retrieve().getAll(tailUrl, GitlabProject[].class);
}

/**
*
* Get a list of projects that the authenticated user is a member of.
*
* @return A list of gitlab projects
* @throws IOException
*/
public List<GitlabProject> getMembershipProjects() throws IOException {
Query query = new Query().append("membership", "true");
query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
String tailUrl = GitlabProject.URL + query.toString();
return retrieve().getAll(tailUrl, GitlabProject[].class);
}

Expand All @@ -653,7 +668,8 @@ public List<GitlabProject> getOwnedProjects() throws IOException {
*/
public List<GitlabProject> getStarredProjects() throws IOException {
Query query = new Query().append("starred", "true");
String tailUrl = GitlabProject.URL + query.toString() + PARAM_MAX_ITEMS_PER_PAGE;
query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
String tailUrl = GitlabProject.URL + query.toString();
return retrieve().getAll(tailUrl, GitlabProject[].class);
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/gitlab/api/GitlabAPIIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ public void testGetGroupByPath() throws IOException {
api.deleteGroup(group.getId());
}

@Test
public void testGetMembershipProjects() throws IOException {
final List<GitlabProject> membershipProjects = api.getMembershipProjects();
assertEquals(0, membershipProjects.size());
}

@Test
public void Check_get_owned_projects() throws IOException {
final List<GitlabProject> ownedProjects = api.getOwnedProjects();
Expand Down

0 comments on commit 14e4766

Please sign in to comment.