Skip to content

Commit

Permalink
Add getDescendantGroups() methods to GroupApi (#907)
Browse files Browse the repository at this point in the history
* Add getDescendantGroups() methods to GroupApi

* Update javadoc
  • Loading branch information
jmini authored Mar 30, 2023
1 parent 336a8c8 commit d8a7ea9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/main/java/org/gitlab4j/api/GroupApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,50 @@ public Stream<Group> getSubGroupsStream(Object groupIdOrPath, List<Integer> skip
return (getSubGroups(groupIdOrPath, skipGroups, allAvailable, search, orderBy, sortOrder, statistics, owned, getDefaultPerPage()).stream());
}

/**
* Get a list of visible descendant groups of a given group for the authenticated user using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/descendant_groups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @param filter the GroupFilter to match against
* @return a List&lt;Group&gt; of the matching groups
* @throws GitLabApiException if any exception occurs
*/
public List<Group> getDescendantGroups(Object groupIdOrPath, GroupFilter filter) throws GitLabApiException {
return (getDescendantGroups(groupIdOrPath, filter, getDefaultPerPage()).all());
}

/**
* Get a Pager of visible descendant groups of a given group for the authenticated user using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/descendant_groups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @param filter the GroupFilter to match against
* @param itemsPerPage the number of Group instances that will be fetched per page
* @return a Pager containing matching Group instances
* @throws GitLabApiException if any exception occurs
*/
public Pager<Group> getDescendantGroups(Object groupIdOrPath, GroupFilter filter, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
return (new Pager<Group>(this, Group.class, itemsPerPage, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "descendant_groups"));
}

/**
* Get a Stream of visible descendant groups of a given group for the authenticated user using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/descendant_groups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @param filter the GroupFilter to match against
* @return a Stream&lt;Group&gt; of the matching groups
* @throws GitLabApiException if any exception occurs
*/
public Stream<Group> getDescendantGroupsStream(Object groupIdOrPath, GroupFilter filter) throws GitLabApiException {
return (getDescendantGroups(groupIdOrPath, filter, getDefaultPerPage()).stream());
}

/**
* Get a list of projects belonging to the specified group ID and filter.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gitlab4j/api/models/GroupFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.gitlab4j.api.GitLabApiForm;

/**
* This class is used to filter Projects when getting lists of projects for a specified group.
* This class is used to filter Groups when getting lists of groups.
*/
public class GroupFilter {

Expand Down

0 comments on commit d8a7ea9

Please sign in to comment.