Skip to content

Commit 14e4766

Browse files
miguelaferreiratimols
authored andcommitted
Add method to retrieve projects that the user is member of (timols#243)
* 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
1 parent e650ce4 commit 14e4766

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/main/java/org/gitlab/api/GitlabAPI.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,22 @@ public List<GitlabProject> getProjects() throws IOException {
640640
*/
641641
public List<GitlabProject> getOwnedProjects() throws IOException {
642642
Query query = new Query().append("owner", "true");
643-
String tailUrl = GitlabProject.URL + query.toString() + PARAM_MAX_ITEMS_PER_PAGE;
643+
query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
644+
String tailUrl = GitlabProject.URL + query.toString();
645+
return retrieve().getAll(tailUrl, GitlabProject[].class);
646+
}
647+
648+
/**
649+
*
650+
* Get a list of projects that the authenticated user is a member of.
651+
*
652+
* @return A list of gitlab projects
653+
* @throws IOException
654+
*/
655+
public List<GitlabProject> getMembershipProjects() throws IOException {
656+
Query query = new Query().append("membership", "true");
657+
query.mergeWith(new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).asQuery());
658+
String tailUrl = GitlabProject.URL + query.toString();
644659
return retrieve().getAll(tailUrl, GitlabProject[].class);
645660
}
646661

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

src/test/java/org/gitlab/api/GitlabAPIIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ public void testGetGroupByPath() throws IOException {
186186
api.deleteGroup(group.getId());
187187
}
188188

189+
@Test
190+
public void testGetMembershipProjects() throws IOException {
191+
final List<GitlabProject> membershipProjects = api.getMembershipProjects();
192+
assertEquals(0, membershipProjects.size());
193+
}
194+
189195
@Test
190196
public void Check_get_owned_projects() throws IOException {
191197
final List<GitlabProject> ownedProjects = api.getOwnedProjects();

0 commit comments

Comments
 (0)