Skip to content

Commit 03de914

Browse files
committed
Added support to fetch subgroups (#126).
1 parent af23f99 commit 03de914

File tree

4 files changed

+206
-1
lines changed

4 files changed

+206
-1
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ public String toString() {
104104
}
105105
}
106106

107+
/** Enum to use for ordering the results of getGroups() and getSubGroups(). */
108+
public enum GroupOrderBy {
109+
110+
NAME, PATH;
111+
private static JacksonJsonEnumHelper<GroupOrderBy> enumHelper = new JacksonJsonEnumHelper<>(GroupOrderBy.class);
112+
113+
@JsonCreator
114+
public static GroupOrderBy forValue(String value) {
115+
return enumHelper.forValue(value);
116+
}
117+
118+
@JsonValue
119+
public String toValue() {
120+
return (enumHelper.toString(this));
121+
}
122+
123+
@Override
124+
public String toString() {
125+
return (enumHelper.toString(this));
126+
}
127+
}
128+
107129
/** Enum to use for specifying the scope when calling getPipelines(). */
108130
public enum PipelineScope {
109131

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

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.gitlab4j.api.models.Group;
1313
import org.gitlab4j.api.models.Member;
1414
import org.gitlab4j.api.models.Project;
15+
import org.gitlab4j.api.models.User;
1516
import org.gitlab4j.api.models.Visibility;
1617

1718
/**
@@ -97,14 +98,132 @@ public List<Group> getGroups(String search, int page, int perPage) throws GitLab
9798
*
9899
* @param search the group name or path search criteria
99100
* @param itemsPerPage the number of Group instances that will be fetched per page
100-
* @return a List containing matching Group instances
101+
* @return a Pager containing matching Group instances
101102
* @throws GitLabApiException if any exception occurs
102103
*/
103104
public Pager<Group> getGroups(String search, int itemsPerPage) throws GitLabApiException {
104105
Form formData = new GitLabApiForm().withParam("search", search);
105106
return (new Pager<Group>(this, Group.class, itemsPerPage, formData.asMap(), "groups"));
106107
}
107108

109+
/**
110+
* Get a list of visible direct subgroups in this group.
111+
*
112+
* <p><code>GET /groups/:id/subgroups</code></p>
113+
*
114+
* @param groupId the group ID to get the sub groups for
115+
* @return a List&lt;Group&gt; containing the group's sub-groups
116+
* @throws GitLabApiException if any exception occurs
117+
* @since GitLab 10.3.0
118+
*/
119+
public List<Group> getSubGroups(Integer groupId) throws GitLabApiException {
120+
return (getSubGroups(groupId, null, null, null, null, null, null, null, 1, getDefaultPerPage()));
121+
}
122+
123+
/**
124+
* Get a list of visible direct subgroups in this group.
125+
*
126+
* <p><code>GET /groups/:id/subgroups</code></p>
127+
*
128+
* @param groupId the group ID to get the sub groups for
129+
* @param skipGroups skip the group IDs passed
130+
* @param allAvailable show all the groups you have access to (defaults to false for authenticated users)
131+
* @param search return the list of authorized groups matching the search criteria
132+
* @param orderBy order groups by NAME or PATH. Default is NAME
133+
* @param sortOrder order groups in ASC or DESC order. Default is ASC
134+
* @param statistics include group statistics (admins only)
135+
* @param owned limit to groups owned by the current user
136+
* @return a List&lt;Group&gt; of the matching subgroups
137+
* @throws GitLabApiException if any exception occurs
138+
* @since GitLab 10.3.0
139+
*/
140+
public List<Group> getSubGroups(Integer groupId, List<Integer> skipGroups, Boolean allAvailable, String search,
141+
GroupOrderBy orderBy, SortOrder sortOrder, Boolean statistics, Boolean owned) throws GitLabApiException {
142+
return (getSubGroups(groupId, skipGroups, allAvailable, search, orderBy, sortOrder, statistics, owned, 1, getDefaultPerPage()));
143+
}
144+
145+
/**
146+
* Get a list of visible direct subgroups in this group.
147+
*
148+
* <p><code>GET /groups/:id/subgroups</code></p>
149+
*
150+
* @param groupId the group ID to get the sub groups for
151+
* @param skipGroups skip the group IDs passed
152+
* @param allAvailable show all the groups you have access to (defaults to false for authenticated users)
153+
* @param search return the list of authorized groups matching the search criteria
154+
* @param orderBy order groups by NAME or PATH. Default is NAME
155+
* @param sortOrder order groups in ASC or DESC order. Default is ASC
156+
* @param statistics include group statistics (admins only)
157+
* @param owned limit to groups owned by the current user
158+
* @param page the page to get
159+
* @param perPage the number of Group instances per page
160+
* @return a List&lt;Group&gt; of the matching subgroups
161+
* @throws GitLabApiException if any exception occurs
162+
* @since GitLab 10.3.0
163+
*/
164+
public List<Group> getSubGroups(Integer groupId, List<Integer> skipGroups, Boolean allAvailable, String search,
165+
GroupOrderBy orderBy, SortOrder sortOrder, Boolean statistics, Boolean owned, int page, int perPage)
166+
throws GitLabApiException {
167+
Form formData = new GitLabApiForm()
168+
.withParam("skip_groups", skipGroups)
169+
.withParam("all_available", allAvailable)
170+
.withParam("search", search)
171+
.withParam("order_by", orderBy)
172+
.withParam("sort_order", sortOrder)
173+
.withParam("statistics", statistics)
174+
.withParam("owned", owned)
175+
.withParam(PAGE_PARAM, page)
176+
.withParam(PER_PAGE_PARAM, perPage);
177+
Response response = get(Response.Status.OK, formData.asMap(), "groups", groupId, "subgroups");
178+
return (response.readEntity(new GenericType<List<Group>>() {}));
179+
}
180+
181+
/**
182+
* Get a Pager of visible direct subgroups in this group.
183+
*
184+
* <p><code>GET /groups/:id/subgroups</code></p>
185+
*
186+
* @param groupId the group ID to get the sub groups for
187+
* @param itemsPerPage the number of Group instances that will be fetched per page
188+
* @return a Pager containing matching Group instances
189+
* @throws GitLabApiException if any exception occurs
190+
* @since GitLab 10.3.0
191+
*/
192+
public Pager<Group> getSubGroups(Integer groupId, int itemsPerPage) throws GitLabApiException {
193+
return (new Pager<Group>(this, Group.class, itemsPerPage, null, "groups", groupId, "subgroups"));
194+
}
195+
196+
/**
197+
* Get a Pager of visible direct subgroups in this group.
198+
*
199+
* <p><code>GET /groups/:id/subgroups</code></p>
200+
*
201+
* @param groupId the group ID to get the sub groups for
202+
* @param skipGroups skip the group IDs passed
203+
* @param allAvailable show all the groups you have access to (defaults to false for authenticated users)
204+
* @param search return the list of authorized groups matching the search criteria
205+
* @param orderBy order groups by NAME or PATH. Default is NAME
206+
* @param sortOrder order groups in ASC or DESC order. Default is ASC
207+
* @param statistics include group statistics (admins only)
208+
* @param owned limit to groups owned by the current user
209+
* @param itemsPerPage the number of Group instances that will be fetched per page
210+
* @return a Pager containing matching Group instances
211+
* @throws GitLabApiException if any exception occurs
212+
* @since GitLab 10.3.0
213+
*/
214+
public Pager<Group> getSubGroups(Integer groupId, List<Integer> skipGroups, Boolean allAvailable, String search,
215+
GroupOrderBy orderBy, SortOrder sortOrder, Boolean statistics, Boolean owned, int itemsPerPage) throws GitLabApiException {
216+
Form formData = new GitLabApiForm()
217+
.withParam("skip_groups", skipGroups)
218+
.withParam("all_available", allAvailable)
219+
.withParam("search", search)
220+
.withParam("order_by", orderBy)
221+
.withParam("sort_order", sortOrder)
222+
.withParam("statistics", statistics)
223+
.withParam("owned", owned);
224+
return (new Pager<Group>(this, Group.class, itemsPerPage, formData.asMap(), "groups", groupId, "subgroups"));
225+
}
226+
108227
/**
109228
* Get a list of projects belonging to the specified group ID.
110229
*

src/main/java/org/gitlab4j/api/models/Group.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,60 @@
1111
@XmlAccessorType(XmlAccessType.FIELD)
1212
public class Group {
1313

14+
public class Statistics {
15+
private Integer storageSize;
16+
private Integer repositorySize;
17+
private Integer lfsObjectsSize;
18+
private Integer jobArtifactsSize;
19+
20+
public Integer getStorageSize() {
21+
return storageSize;
22+
}
23+
24+
public void setStorageSize(Integer storageSize) {
25+
this.storageSize = storageSize;
26+
}
27+
28+
public Integer getRepositorySize() {
29+
return repositorySize;
30+
}
31+
32+
public void setRepositorySize(Integer repositorySize) {
33+
this.repositorySize = repositorySize;
34+
}
35+
36+
public Integer getLfsObjectsSize() {
37+
return lfsObjectsSize;
38+
}
39+
40+
public void setLfsObjectsSize(Integer lfsObjectsSize) {
41+
this.lfsObjectsSize = lfsObjectsSize;
42+
}
43+
44+
public Integer getJobArtifactsSize() {
45+
return jobArtifactsSize;
46+
}
47+
48+
public void setJobArtifactsSize(Integer jobArtifactsSize) {
49+
this.jobArtifactsSize = jobArtifactsSize;
50+
}
51+
}
52+
53+
1454
private Integer id;
1555
private String name;
1656
private String path;
1757
private String description;
1858
private Visibility visibility;
59+
private Boolean lfsEnabled;
1960
private String avatarUrl;
2061
private String webUrl;
2162
private Boolean requestAccessEnabled;
2263
private String fullName;
2364
private String fullPath;
2465
private Integer parentId;
2566
private Integer sharedRunnersMinutesLimit;
67+
private Statistics statistics;
2668
private List<Project> projects;
2769
private List<Project> sharedProjects;
2870

@@ -66,6 +108,14 @@ public void setVisibility(Visibility visibility) {
66108
this.visibility = visibility;
67109
}
68110

111+
public Boolean getLfsEnabled() {
112+
return lfsEnabled;
113+
}
114+
115+
public void setLfsEnabled(Boolean lfsEnabled) {
116+
this.lfsEnabled = lfsEnabled;
117+
}
118+
69119
public String getAvatarUrl() {
70120
return avatarUrl;
71121
}
@@ -122,6 +172,14 @@ public void setSharedRunnersMinutesLimit(Integer sharedRunnersMinutesLimit) {
122172
this.sharedRunnersMinutesLimit = sharedRunnersMinutesLimit;
123173
}
124174

175+
public Statistics getStatistics() {
176+
return statistics;
177+
}
178+
179+
public void setStatistics(Statistics statistics) {
180+
this.statistics = statistics;
181+
}
182+
125183
public List<Project> getProjects() {
126184
return (projects);
127185
}

src/test/resources/org/gitlab4j/api/group.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
"full_path": "twitter",
1111
"parent_id": 1234,
1212
"shared_runners_minutes_limit": 133,
13+
"statistics": {
14+
"storage_size" : 212,
15+
"repository_size" : 33,
16+
"lfs_objects_size" : 123,
17+
"job_artifacts_size" : 57
18+
},
1319
"projects": [
1420
{
1521
"id": 7,

0 commit comments

Comments
 (0)