Skip to content

Commit 0bfeacb

Browse files
committed
allow fetching groups w/o projects
1 parent f03eedf commit 0bfeacb

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

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

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

4040
private static final String DEFAULT_API_NAMESPACE = "/api/v4";
4141
private static final String PARAM_SUDO = "sudo";
42+
private static final String PARAM_WITH_PROJECTS = "with_projects";
4243
private static final String PARAM_MAX_ITEMS_PER_PAGE = new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).toString();
4344

4445
private final String hostUrl;
@@ -464,17 +465,49 @@ public GitlabGroup getGroup(Integer groupId) throws IOException {
464465
return getGroup(groupId.toString());
465466
}
466467

468+
public GitlabGroup getGroupWithoutProjects(Integer groupId) throws IOException {
469+
return getGroupWithoutProjects(groupId.toString());
470+
}
471+
467472
/**
468-
* Get a group by path
473+
* Get a group by path. Don't include the projects.
474+
*
475+
* @param path Path of the group
476+
* @return {@link GitlabGroup} object
477+
*
478+
* @throws IOException on gitlab api call error
479+
*/
480+
public GitlabGroup getGroupWithoutProjects(String path) throws IOException {
481+
return getGroup(path, false);
482+
}
483+
484+
/**
485+
* Get a group by path, including its projects.
469486
*
470487
* @param path Path of the group
471488
* @return {@link GitlabGroup} object
472489
*
473490
* @throws IOException on gitlab api call error
474491
*/
475492
public GitlabGroup getGroup(String path) throws IOException {
493+
return getGroup(path, true);
494+
}
495+
496+
/**
497+
* Get a group by path
498+
*
499+
* @param path Path of the group
500+
* @param withProjects If true, include the projects
501+
* @return {@link GitlabGroup} object
502+
*
503+
* @throws IOException on gitlab api call error
504+
*/
505+
public GitlabGroup getGroup(String path, boolean withProjects) throws IOException {
476506
String tailUrl = GitlabGroup.URL + "/" + URLEncoder.encode(path, "UTF-8");
477-
return retrieve().to(tailUrl, GitlabGroup.class);
507+
Query query = new Query()
508+
.append(PARAM_WITH_PROJECTS, "" + withProjects);
509+
510+
return retrieve().to(tailUrl + query.toString(), GitlabGroup.class);
478511
}
479512

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

0 commit comments

Comments
 (0)