Skip to content

Commit e95af61

Browse files
committed
Added support to get groups with filter (#302).
1 parent 5a7f99c commit e95af61

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/main/java/org/gitlab4j/api/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public String toString() {
180180
/** Enum to use for ordering the results of getGroups() and getSubGroups(). */
181181
public enum GroupOrderBy {
182182

183-
NAME, PATH;
183+
NAME, PATH, ID;
184184
private static JacksonJsonEnumHelper<GroupOrderBy> enumHelper = new JacksonJsonEnumHelper<>(GroupOrderBy.class);
185185

186186
@JsonCreator

src/main/java/org/gitlab4j/api/GroupApi.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.gitlab4j.api.GitLabApi.ApiVersion;
1313
import org.gitlab4j.api.models.AccessLevel;
1414
import org.gitlab4j.api.models.Group;
15+
import org.gitlab4j.api.models.GroupFilter;
1516
import org.gitlab4j.api.models.Member;
1617
import org.gitlab4j.api.models.Project;
1718
import org.gitlab4j.api.models.GroupProjectsFilter;
@@ -128,6 +129,47 @@ public Stream<Group> getGroupsStream(String search) throws GitLabApiException {
128129
return (getGroups(search, getDefaultPerPage()).stream());
129130
}
130131

132+
/**
133+
* Get a list of visible groups for the authenticated user using the provided filter.
134+
*
135+
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
136+
*
137+
* @param filter the GroupFilter to match against
138+
* @return a List&lt;Group&gt; of the matching groups
139+
* @throws GitLabApiException if any exception occurs
140+
*/
141+
public List<Group> getGroups(GroupFilter filter) throws GitLabApiException {
142+
return (getGroups(filter, getDefaultPerPage()).all());
143+
}
144+
145+
/**
146+
* Get a Pager of visible groups for the authenticated user using the provided filter.
147+
*
148+
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
149+
*
150+
* @param filter the GroupFilter to match against
151+
* @param itemsPerPage the number of Group instances that will be fetched per page
152+
* @return a Pager containing matching Group instances
153+
* @throws GitLabApiException if any exception occurs
154+
*/
155+
public Pager<Group> getGroups(GroupFilter filter, int itemsPerPage) throws GitLabApiException {
156+
GitLabApiForm formData = filter.getQueryParams();
157+
return (new Pager<Group>(this, Group.class, itemsPerPage, formData.asMap(), "groups"));
158+
}
159+
160+
/**
161+
* Get a Stream of visible groups for the authenticated user using the provided filter.
162+
*
163+
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
164+
*
165+
* @param filter the GroupFilter to match against
166+
* @return a Stream&lt;Group&gt; of the matching groups
167+
* @throws GitLabApiException if any exception occurs
168+
*/
169+
public Stream<Group> getGroupsStream(GroupFilter filter) throws GitLabApiException {
170+
return (getGroups(filter, getDefaultPerPage()).stream());
171+
}
172+
131173
/**
132174
* Get a list of visible direct subgroups in this group.
133175
*

0 commit comments

Comments
 (0)