Skip to content

Commit c324891

Browse files
committed
GroupScript: add actions to read groups
1 parent e0a5467 commit c324891

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

gitlab4j-test/GroupScript.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class GroupScript implements Callable<Integer> {
4242
Boolean logHttp;
4343

4444
private static enum Action {
45-
GET_GROUP, GET_GROUP_LABELS, GET_GROUP_UPLOADS
45+
GET_GROUP, GET_ALL_GROUPS, GET_SUB_GROUPS, GET_DESCENDANT_GROUPS, GET_GROUP_LABELS, GET_GROUP_UPLOADS
4646
}
4747

4848
@Override
@@ -58,7 +58,6 @@ public Integer call() throws Exception {
5858
final String gitLabUrl = readProperty(prop, "GITLAB_URL", "https://gitlab.com");
5959
final String gitLabAuthValue = readProperty(prop, "GITLAB_AUTH_VALUE");
6060

61-
6261
try (GitLabApi gitLabApi = createGitLabApi(gitLabUrl, gitLabAuthValue)) {
6362
switch (action) {
6463
case GET_GROUP:
@@ -67,6 +66,32 @@ public Integer call() throws Exception {
6766
.getGroup(idOrPath(group));
6867
System.out.println(groupResponse);
6968
break;
69+
case GET_ALL_GROUPS:
70+
var groups = gitLabApi.getGroupApi()
71+
.getGroups();
72+
groups.stream()
73+
.sorted(Comparator.comparing(Group::getFullName))
74+
.forEach(g -> {
75+
System.out.println(g.getFullName());
76+
});
77+
break;
78+
case GET_SUB_GROUPS:
79+
ensureExists(group, "group");
80+
var subGroups = gitLabApi.getGroupApi()
81+
.getSubGroups(idOrPath(group));
82+
for (Group g : subGroups) {
83+
System.out.println(g.getFullName());
84+
}
85+
break;
86+
case GET_DESCENDANT_GROUPS:
87+
ensureExists(group, "group");
88+
var descendantGroups = gitLabApi.getGroupApi()
89+
.getDescendantGroups(idOrPath(group), new GroupFilter()
90+
.withAllAvailable(true));
91+
for (Group g : descendantGroups) {
92+
System.out.println(g.getFullName());
93+
}
94+
break;
7095
case GET_GROUP_LABELS:
7196
ensureExists(group, "group");
7297
var labelsResponse = gitLabApi.getLabelsApi()
@@ -89,12 +114,11 @@ public Integer call() throws Exception {
89114
private GitLabApi createGitLabApi(String gitLabUrl, String gitLabAuthValue) {
90115
if (logHttp != null && logHttp) {
91116
return new GitLabApi(gitLabUrl, gitLabAuthValue)
92-
.withRequestResponseLogging(java.util.logging.Level.INFO) ;
117+
.withRequestResponseLogging(java.util.logging.Level.INFO);
93118
}
94119
return new GitLabApi(gitLabUrl, gitLabAuthValue);
95120
}
96121

97-
98122
private void ensureExists(Object value, String optionName) {
99123
if (value == null) {
100124
throw new IllegalStateException("--" + optionName + " must be set");

0 commit comments

Comments
 (0)