Skip to content

Commit dbf2e74

Browse files
novalistimols
authored andcommitted
allow fetching groups w/o projects (timols#359)
1 parent 75cd3e4 commit dbf2e74

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class GitlabAPI {
4242

4343
private static final String DEFAULT_API_NAMESPACE = "/api/v4";
4444
private static final String PARAM_SUDO = "sudo";
45+
private static final String PARAM_WITH_PROJECTS = "with_projects";
4546
private static final String PARAM_MAX_ITEMS_PER_PAGE = new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).toString();
4647

4748
private final String hostUrl;
@@ -467,17 +468,49 @@ public GitlabGroup getGroup(Integer groupId) throws IOException {
467468
return getGroup(groupId.toString());
468469
}
469470

471+
public GitlabGroup getGroupWithoutProjects(Integer groupId) throws IOException {
472+
return getGroupWithoutProjects(groupId.toString());
473+
}
474+
470475
/**
471-
* Get a group by path
476+
* Get a group by path. Don't include the projects.
477+
*
478+
* @param path Path of the group
479+
* @return {@link GitlabGroup} object
480+
*
481+
* @throws IOException on gitlab api call error
482+
*/
483+
public GitlabGroup getGroupWithoutProjects(String path) throws IOException {
484+
return getGroup(path, false);
485+
}
486+
487+
/**
488+
* Get a group by path, including its projects.
472489
*
473490
* @param path Path of the group
474491
* @return {@link GitlabGroup} object
475492
*
476493
* @throws IOException on gitlab api call error
477494
*/
478495
public GitlabGroup getGroup(String path) throws IOException {
496+
return getGroup(path, true);
497+
}
498+
499+
/**
500+
* Get a group by path
501+
*
502+
* @param path Path of the group
503+
* @param withProjects If true, include the projects
504+
* @return {@link GitlabGroup} object
505+
*
506+
* @throws IOException on gitlab api call error
507+
*/
508+
public GitlabGroup getGroup(String path, boolean withProjects) throws IOException {
479509
String tailUrl = GitlabGroup.URL + "/" + URLEncoder.encode(path, "UTF-8");
480-
return retrieve().to(tailUrl, GitlabGroup.class);
510+
Query query = new Query()
511+
.append(PARAM_WITH_PROJECTS, "" + withProjects);
512+
513+
return retrieve().to(tailUrl + query.toString(), GitlabGroup.class);
481514
}
482515

483516
public List<GitlabGroup> getGroups() throws IOException {

0 commit comments

Comments
 (0)