forked from gitlab4j/gitlab4j-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupApi.java
2457 lines (2291 loc) · 112 KB
/
GroupApi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.gitlab4j.api;
import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.*;
import org.gitlab4j.api.models.ImpersonationToken.Scope;
import org.gitlab4j.api.utils.ISO8601;
/**
* This class implements the client side API for the GitLab groups calls.
* @see <a href="https://docs.gitlab.com/ce/api/groups.html">Groups API at GitLab</a>
* @see <a href="https://docs.gitlab.com/ce/api/members.html">Group and project members API at GitLab</a>
* @see <a href="https://docs.gitlab.com/ce/api/access_requests.html">Group and project access requests API</a>
* @see <a href="https://docs.gitlab.com/ce/api/group_badges.html">Group badges API</a>
* @see <a href="https://docs.gitlab.com/ee/api/audit_events.html#retrieve-all-group-audit-events">Group audit events API</a>
*/
public class GroupApi extends AbstractApi {
public GroupApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* <p>Get a list of groups. (As user: my groups, as admin: all groups)</p>
*
* <strong>WARNING:</strong> Do not use this method to fetch groups from https://gitlab.com,
* gitlab.com has many 1,000's of public groups and it will a long time to fetch all of them.
* Instead use {@link #getGroups(int itemsPerPage)} which will return a Pager of Group instances.
*
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
*
* @return the list of groups viewable by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public List<Group> getGroups() throws GitLabApiException {
String url = this.gitLabApi.getGitLabServerUrl();
if (url.startsWith("https://gitlab.com")) {
GitLabApi.getLogger()
.warning("Fetching all groups from " + url
+ " may take many minutes to complete, use Pager<Group> getGroups(int) instead.");
}
return (getGroups(getDefaultPerPage()).all());
}
/**
* Get a list of groups (As user: my groups, as admin: all groups) and in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
*
* @param page the page to get
* @param perPage the number of Group instances per page
* @return the list of groups viewable by the authenticated userin the specified page range
* @throws GitLabApiException if any exception occurs
*/
public List<Group> getGroups(int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "groups");
return (response.readEntity(new GenericType<List<Group>>() {}));
}
/**
* Get a Pager of groups. (As user: my groups, as admin: all groups)
*
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
*
* @param itemsPerPage the number of Group instances that will be fetched per page
* @return the list of groups viewable by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Pager<Group> getGroups(int itemsPerPage) throws GitLabApiException {
return (new Pager<Group>(this, Group.class, itemsPerPage, null, "groups"));
}
/**
* Get a Stream of groups. (As user: my groups, as admin: all groups)
*
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
*
* @return a Stream of groups viewable by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Stream<Group> getGroupsStream() throws GitLabApiException {
return (getGroups(getDefaultPerPage()).stream());
}
/**
* Get all groups that match your string in their name or path.
*
* @param search the group name or path search criteria
* @return a List containing matching Group instances
* @throws GitLabApiException if any exception occurs
*/
public List<Group> getGroups(String search) throws GitLabApiException {
return (getGroups(search, getDefaultPerPage()).all());
}
/**
* Get all groups that match your string in their name or path.
*
* @param search the group name or path search criteria
* @param page the page to get
* @param perPage the number of Group instances per page
* @return a List containing matching Group instances
* @throws GitLabApiException if any exception occurs
*/
public List<Group> getGroups(String search, int page, int perPage) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("search", search)
.withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "groups");
return (response.readEntity(new GenericType<List<Group>>() {}));
}
/**
* Get all groups that match your string in their name or path.
*
* @param search the group name or path search criteria
* @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> getGroups(String search, int itemsPerPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("search", search);
return (new Pager<Group>(this, Group.class, itemsPerPage, formData.asMap(), "groups"));
}
/**
* Get all groups that match your string in their name or path as a Stream.
*
* @param search the group name or path search criteria
* @return a Stream containing matching Group instances
* @throws GitLabApiException if any exception occurs
*/
public Stream<Group> getGroupsStream(String search) throws GitLabApiException {
return (getGroups(search, getDefaultPerPage()).stream());
}
/**
* Get a list of visible groups for the authenticated user using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
*
* @param filter the GroupFilter to match against
* @return a List<Group> of the matching groups
* @throws GitLabApiException if any exception occurs
*/
public List<Group> getGroups(GroupFilter filter) throws GitLabApiException {
return (getGroups(filter, getDefaultPerPage()).all());
}
/**
* Get a Pager of visible groups for the authenticated user using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
*
* @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> getGroups(GroupFilter filter, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
return (new Pager<Group>(this, Group.class, itemsPerPage, formData.asMap(), "groups"));
}
/**
* Get a Stream of visible groups for the authenticated user using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /groups</code></pre>
*
* @param filter the GroupFilter to match against
* @return a Stream<Group> of the matching groups
* @throws GitLabApiException if any exception occurs
*/
public Stream<Group> getGroupsStream(GroupFilter filter) throws GitLabApiException {
return (getGroups(filter, getDefaultPerPage()).stream());
}
/**
* Get a list of visible direct subgroups in this group.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @return a List<Group> containing the group's sub-groups
* @throws GitLabApiException if any exception occurs
* @since GitLab 10.3.0
*/
public List<Group> getSubGroups(Object groupIdOrPath) throws GitLabApiException {
return (getSubGroups(groupIdOrPath, getDefaultPerPage()).all());
}
/**
* Get a Pager of visible direct subgroups in this group.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @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
* @since GitLab 10.3.0
*/
public Pager<Group> getSubGroups(Object groupIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Group>(
this, Group.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "subgroups"));
}
/**
* Get a Stream of visible direct subgroups in this group.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @return a Stream<Group> containing the group's sub-groups
* @throws GitLabApiException if any exception occurs
* @since GitLab 10.3.0
*/
public Stream<Group> getSubGroupsStream(Object groupIdOrPath) throws GitLabApiException {
return (getSubGroups(groupIdOrPath, getDefaultPerPage()).stream());
}
/**
* Get a list of visible direct subgroups in this group.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @param skipGroups skip the group IDs passed
* @param allAvailable show all the groups you have access to (defaults to false for authenticated users)
* @param search return the list of authorized groups matching the search criteria
* @param orderBy order groups by NAME or PATH. Default is NAME
* @param sortOrder order groups in ASC or DESC order. Default is ASC
* @param statistics include group statistics (admins only)
* @param owned limit to groups owned by the current user
* @return a List<Group> of the matching subgroups
* @throws GitLabApiException if any exception occurs
* @since GitLab 10.3.0
*/
public List<Group> getSubGroups(
Object groupIdOrPath,
List<Integer> skipGroups,
Boolean allAvailable,
String search,
GroupOrderBy orderBy,
SortOrder sortOrder,
Boolean statistics,
Boolean owned)
throws GitLabApiException {
return (getSubGroups(
groupIdOrPath,
skipGroups,
allAvailable,
search,
orderBy,
sortOrder,
statistics,
owned,
getDefaultPerPage())
.all());
}
/**
* Get a list of visible direct subgroups in this group.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @param skipGroups skip the group IDs passed
* @param allAvailable show all the groups you have access to (defaults to false for authenticated users)
* @param search return the list of authorized groups matching the search criteria
* @param orderBy order groups by NAME or PATH. Default is NAME
* @param sortOrder order groups in ASC or DESC order. Default is ASC
* @param statistics include group statistics (admins only)
* @param owned limit to groups owned by the current user
* @param page the page to get
* @param perPage the number of Group instances per page
* @return a List<Group> of the matching subgroups
* @throws GitLabApiException if any exception occurs
* @since GitLab 10.3.0
*/
public List<Group> getSubGroups(
Object groupIdOrPath,
List<Integer> skipGroups,
Boolean allAvailable,
String search,
GroupOrderBy orderBy,
SortOrder sortOrder,
Boolean statistics,
Boolean owned,
int page,
int perPage)
throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("skip_groups", skipGroups)
.withParam("all_available", allAvailable)
.withParam("search", search)
.withParam("order_by", orderBy)
.withParam("sort_order", sortOrder)
.withParam("statistics", statistics)
.withParam("owned", owned)
.withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage);
Response response =
get(Response.Status.OK, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "subgroups");
return (response.readEntity(new GenericType<List<Group>>() {}));
}
/**
* Get a Pager of visible direct subgroups in this group.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @param skipGroups skip the group IDs passed
* @param allAvailable show all the groups you have access to (defaults to false for authenticated users)
* @param search return the list of authorized groups matching the search criteria
* @param orderBy order groups by NAME or PATH. Default is NAME
* @param sortOrder order groups in ASC or DESC order. Default is ASC
* @param statistics include group statistics (admins only)
* @param owned limit to groups owned by the current user
* @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
* @since GitLab 10.3.0
*/
public Pager<Group> getSubGroups(
Object groupIdOrPath,
List<Integer> skipGroups,
Boolean allAvailable,
String search,
GroupOrderBy orderBy,
SortOrder sortOrder,
Boolean statistics,
Boolean owned,
int itemsPerPage)
throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("skip_groups", skipGroups)
.withParam("all_available", allAvailable)
.withParam("search", search)
.withParam("order_by", orderBy)
.withParam("sort_order", sortOrder)
.withParam("statistics", statistics)
.withParam("owned", owned);
return (new Pager<Group>(
this,
Group.class,
itemsPerPage,
formData.asMap(),
"groups",
getGroupIdOrPath(groupIdOrPath),
"subgroups"));
}
/**
* Get a Stream of visible direct subgroups in this group.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/subgroups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required
* @param skipGroups skip the group IDs passed
* @param allAvailable show all the groups you have access to (defaults to false for authenticated users)
* @param search return the list of authorized groups matching the search criteria
* @param orderBy order groups by NAME or PATH. Default is NAME
* @param sortOrder order groups in ASC or DESC order. Default is ASC
* @param statistics include group statistics (admins only)
* @param owned limit to groups owned by the current user
* @return a Stream<Group> of the matching subgroups
* @throws GitLabApiException if any exception occurs
* @since GitLab 10.3.0
*/
public Stream<Group> getSubGroupsStream(
Object groupIdOrPath,
List<Integer> skipGroups,
Boolean allAvailable,
String search,
GroupOrderBy orderBy,
SortOrder sortOrder,
Boolean statistics,
Boolean owned)
throws GitLabApiException {
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<Group> 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<Group> 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.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/projects</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param filter the GroupProjectsFilter instance holding the filter values for the query
* @return a List containing Project instances that belong to the group and match the provided filter
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(Object groupIdOrPath, GroupProjectsFilter filter) throws GitLabApiException {
return (getProjects(groupIdOrPath, filter, getDefaultPerPage()).all());
}
/**
* Get a Pager of projects belonging to the specified group ID and filter.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/projects</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param filter the GroupProjectsFilter instance holding the filter values for the query
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager containing Project instances that belong to the group and match the provided filter
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getProjects(Object groupIdOrPath, GroupProjectsFilter filter, int itemsPerPage)
throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
return (new Pager<Project>(
this,
Project.class,
itemsPerPage,
formData.asMap(),
"groups",
getGroupIdOrPath(groupIdOrPath),
"projects"));
}
/**
* Get a Stream of projects belonging to the specified group ID and filter.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/projects</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param filter the GroupProjectsFilter instance holding the filter values for the query
* @return a Stream containing Project instances that belong to the group and match the provided filter
* @throws GitLabApiException if any exception occurs
*/
public Stream<Project> getProjectsStream(Object groupIdOrPath, GroupProjectsFilter filter)
throws GitLabApiException {
return (getProjects(groupIdOrPath, filter, getDefaultPerPage()).stream());
}
/**
* Get a list of projects belonging to the specified group ID.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/projects</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @return a list of projects belonging to the specified group ID
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(Object groupIdOrPath) throws GitLabApiException {
return (getProjects(groupIdOrPath, getDefaultPerPage()).all());
}
/**
* Get a list of projects belonging to the specified group ID in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/projects</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param page the page to get
* @param perPage the number of Project instances per page
* @return a list of projects belonging to the specified group ID in the specified page range
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(Object groupIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(
Response.Status.OK,
getPageQueryParams(page, perPage),
"groups",
getGroupIdOrPath(groupIdOrPath),
"projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}
/**
* Get a Pager of projects belonging to the specified group ID.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/projects</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of projects belonging to the specified group ID
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getProjects(Object groupIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Project>(
this, Project.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "projects"));
}
/**
* Get a Stream of projects belonging to the specified group ID.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/projects</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @return a Stream of projects belonging to the specified group ID
* @throws GitLabApiException if any exception occurs
*/
public Stream<Project> getProjectsStream(Object groupIdOrPath) throws GitLabApiException {
return (getProjects(groupIdOrPath, getDefaultPerPage()).stream());
}
/**
* Get all details of a group.
*
* <pre><code>GitLab Endpoint: GET /groups/:id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @return the Group instance for the specified group path
* @throws GitLabApiException if any exception occurs
*/
public Group getGroup(Object groupIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath));
return (response.readEntity(Group.class));
}
/**
* Get all details of a group as an Optional instance.
*
* <pre><code>GitLab Endpoint: GET /groups/:id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @return the Group for the specified group path as an Optional instance
*/
public Optional<Group> getOptionalGroup(Object groupIdOrPath) {
try {
return (Optional.ofNullable(getGroup(groupIdOrPath)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Creates a new project group. Available only for users who can create groups.
*
* <pre><code>GitLab Endpoint: POST /groups</code></pre>
*
* @param params a GroupParams instance holding the parameters for the group creation
* @return the created Group instance
* @throws GitLabApiException if any exception occurs
*/
public Group createGroup(GroupParams params) throws GitLabApiException {
Response response = post(Response.Status.CREATED, params.getForm(true), "groups");
return (response.readEntity(Group.class));
}
/**
* Updates the project group. Only available to group owners and administrators.
*
* <pre><code>GitLab Endpoint: PUT /groups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param params the GroupParams instance holding the properties to update
* @return updated Group instance
* @throws GitLabApiException at any exception
*/
public Group updateGroup(Object groupIdOrPath, GroupParams params) throws GitLabApiException {
Response response =
putWithFormData(Response.Status.OK, params.getForm(false), "groups", getGroupIdOrPath(groupIdOrPath));
return (response.readEntity(Group.class));
}
/**
* Creates a new project group. Available only for users who can create groups.
*
* <pre><code>GitLab Endpoint: POST /groups</code></pre>
*
* @param name the name of the group to add
* @param path the path for the group
* @return the created Group instance
* @throws GitLabApiException if any exception occurs
*/
public Group addGroup(String name, String path) throws GitLabApiException {
Form formData = new Form();
formData.param("name", name);
formData.param("path", path);
Response response = post(Response.Status.CREATED, formData, "groups");
return (response.readEntity(Group.class));
}
public Group addGroup(Group group) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("name", group.getName(), true)
.withParam("path", group.getPath(), true)
.withParam("description", group.getDescription())
.withParam("visibility", group.getVisibility())
.withParam("lfs_enabled", group.getLfsEnabled())
.withParam("request_access_enabled", group.getRequestAccessEnabled())
.withParam("parent_id", isApiVersion(ApiVersion.V3) ? null : group.getParentId());
Response response = post(Response.Status.CREATED, formData, "groups");
return (response.readEntity(Group.class));
}
/**
* Creates a new project group. Available only for users who can create groups.
*
* <pre><code>GitLab Endpoint: POST /groups</code></pre>
*
* @param name the name of the group to add
* @param path the path for the group
* @param description (optional) - The group's description
* @param visibility (optional) - The group's visibility. Can be private, internal, or public.
* @param lfsEnabled (optional) - Enable/disable Large File Storage (LFS) for the projects in this group
* @param requestAccessEnabled (optional) - Allow users to request member access
* @param parentId (optional) - The parent group id for creating nested group
* @return the created Group instance
* @throws GitLabApiException if any exception occurs
*/
public Group addGroup(
String name,
String path,
String description,
Visibility visibility,
Boolean lfsEnabled,
Boolean requestAccessEnabled,
Long parentId)
throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("name", name, true)
.withParam("path", path, true)
.withParam("description", description)
.withParam("visibility", visibility)
.withParam("lfs_enabled", lfsEnabled)
.withParam("request_access_enabled", requestAccessEnabled)
.withParam("parent_id", isApiVersion(ApiVersion.V3) ? null : parentId);
Response response = post(Response.Status.CREATED, formData, "groups");
return (response.readEntity(Group.class));
}
/**
* Updates a project group. Available only for users who can create groups.
*
* <pre><code>GitLab Endpoint: PUT /groups</code></pre>
*
* @param group to update
* @return updated group instance
* @throws GitLabApiException at any exception
*/
public Group updateGroup(Group group) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("name", group.getName())
.withParam("path", group.getPath())
.withParam("description", group.getDescription())
.withParam("visibility", group.getVisibility())
.withParam("lfs_enabled", group.getLfsEnabled())
.withParam("request_access_enabled", group.getRequestAccessEnabled())
.withParam("parent_id", isApiVersion(ApiVersion.V3) ? null : group.getParentId());
Response response = put(Response.Status.OK, formData.asMap(), "groups", group.getId());
return (response.readEntity(Group.class));
}
/**
* Updates a project group. Available only for users who can create groups.
*
* <pre><code>GitLab Endpoint: PUT /groups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param name the name of the group to add
* @param path the path for the group
* @param description (optional) - The group's description
* @param visibility (optional) - The group's visibility. Can be private, internal, or public.
* @param lfsEnabled (optional) - Enable/disable Large File Storage (LFS) for the projects in this group
* @param requestAccessEnabled (optional) - Allow users to request member access
* @param parentId (optional) - The parent group id for creating nested group
* @return the updated Group instance
* @throws GitLabApiException if any exception occurs
*/
public Group updateGroup(
Object groupIdOrPath,
String name,
String path,
String description,
Visibility visibility,
Boolean lfsEnabled,
Boolean requestAccessEnabled,
Long parentId)
throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("name", name)
.withParam("path", path)
.withParam("description", description)
.withParam("visibility", visibility)
.withParam("lfs_enabled", lfsEnabled)
.withParam("request_access_enabled", requestAccessEnabled)
.withParam("parent_id", isApiVersion(ApiVersion.V3) ? null : parentId);
Response response = put(Response.Status.OK, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath));
return (response.readEntity(Group.class));
}
/**
* Creates a new project group. Available only for users who can create groups.
*
* <pre><code>GitLab Endpoint: POST /groups</code></pre>
*
* @param name the name of the group to add
* @param path the path for the group
* @param description (optional) - The group's description
* @param membershipLock (optional, boolean) - Prevent adding new members to project membership within this group
* @param shareWithGroupLock (optional, boolean) - Prevent sharing a project with another group within this group
* @param visibility (optional) - The group's visibility. Can be private, internal, or public.
* @param lfsEnabled (optional) - Enable/disable Large File Storage (LFS) for the projects in this group
* @param requestAccessEnabled (optional) - Allow users to request member access.
* @param parentId (optional) - The parent group id for creating nested group.
* @param sharedRunnersMinutesLimit (optional) - (admin-only) Pipeline minutes quota for this group
* @return the created Group instance
* @throws GitLabApiException if any exception occurs
* @deprecated Will be removed in version 6.0, replaced by {@link #addGroup(String, String, String, Visibility,
* Boolean, Boolean, Long)}
*/
@Deprecated
public Group addGroup(
String name,
String path,
String description,
Boolean membershipLock,
Boolean shareWithGroupLock,
Visibility visibility,
Boolean lfsEnabled,
Boolean requestAccessEnabled,
Long parentId,
Integer sharedRunnersMinutesLimit)
throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("name", name)
.withParam("path", path)
.withParam("description", description)
.withParam("membership_lock", membershipLock)
.withParam("share_with_group_lock", shareWithGroupLock)
.withParam("visibility", visibility)
.withParam("lfs_enabled", lfsEnabled)
.withParam("request_access_enabled", requestAccessEnabled)
.withParam("parent_id", parentId)
.withParam("shared_runners_minutes_limit", sharedRunnersMinutesLimit);
Response response = post(Response.Status.CREATED, formData, "groups");
return (response.readEntity(Group.class));
}
/**
* Updates a project group. Available only for users who can create groups.
*
* <pre><code>GitLab Endpoint: PUT /groups</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param name the name of the group to add
* @param path the path for the group
* @param description (optional) - The group's description
* @param membershipLock (optional, boolean) - Prevent adding new members to project membership within this group
* @param shareWithGroupLock (optional, boolean) - Prevent sharing a project with another group within this group
* @param visibility (optional) - The group's visibility. Can be private, internal, or public.
* @param lfsEnabled (optional) - Enable/disable Large File Storage (LFS) for the projects in this group
* @param requestAccessEnabled (optional) - Allow users to request member access
* @param parentId (optional) - The parent group id for creating nested group
* @param sharedRunnersMinutesLimit (optional) - (admin-only) Pipeline minutes quota for this group
* @return the updated Group instance
* @throws GitLabApiException if any exception occurs
* @deprecated Will be removed in version 6.0, replaced by {@link #updateGroup(Object, String, String, String,
* Visibility, Boolean, Boolean, Long)}
*/
@Deprecated
public Group updateGroup(
Object groupIdOrPath,
String name,
String path,
String description,
Boolean membershipLock,
Boolean shareWithGroupLock,
Visibility visibility,
Boolean lfsEnabled,
Boolean requestAccessEnabled,
Long parentId,
Integer sharedRunnersMinutesLimit)
throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("name", name)
.withParam("path", path)
.withParam("description", description)
.withParam("membership_lock", membershipLock)
.withParam("share_with_group_lock", shareWithGroupLock)
.withParam("visibility", visibility)
.withParam("lfs_enabled", lfsEnabled)
.withParam("request_access_enabled", requestAccessEnabled)
.withParam("parent_id", parentId)
.withParam("shared_runners_minutes_limit", sharedRunnersMinutesLimit);
Response response = put(Response.Status.OK, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath));
return (response.readEntity(Group.class));
}
/**
* Removes group with all projects inside.
*
* <pre><code>GitLab Endpoint: DELETE /groups/:id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @throws GitLabApiException if any exception occurs
*/
public void deleteGroup(Object groupIdOrPath) throws GitLabApiException {
Response.Status expectedStatus =
(isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "groups", getGroupIdOrPath(groupIdOrPath));
}
/**
* Get a list of group members viewable by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/members</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @return a list of group members viewable by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public List<Member> getMembers(Object groupIdOrPath) throws GitLabApiException {
return (getMembers(groupIdOrPath, getDefaultPerPage()).all());
}
/**
* Get a list of group members viewable by the authenticated user in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/members</code></pre>
*
*@param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param page the page to get
* @param perPage the number of Member instances per page
* @return a list of group members viewable by the authenticated user in the specified page range
* @throws GitLabApiException if any exception occurs
*/
public List<Member> getMembers(Object groupIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(
Response.Status.OK,
getPageQueryParams(page, perPage),
"groups",
getGroupIdOrPath(groupIdOrPath),
"members");
return (response.readEntity(new GenericType<List<Member>>() {}));
}
/**
* Get a Pager of group members viewable by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/members</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param itemsPerPage the number of Member instances that will be fetched per page
* @return a list of group members viewable by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Pager<Member> getMembers(Object groupIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Member>(
this, Member.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "members"));
}
/**
* Get a Stream of group members viewable by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/members</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @return a Stream of group members viewable by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Stream<Member> getMembersStream(Object groupIdOrPath) throws GitLabApiException {
return (getMembers(groupIdOrPath, getDefaultPerPage()).stream());
}
/**
* Get a group member viewable by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/members/:id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param userId the member ID of the member to get
* @return a member viewable by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Member getMember(Object groupIdOrPath, long userId) throws GitLabApiException {
return (getMember(groupIdOrPath, userId, false));
}
/**
* Get a group member viewable by the authenticated user as an Optional instance.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/members/:id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param userId the member ID of the member to get
* @return a member viewable by the authenticated user as an Optional instance
*/
public Optional<Member> getOptionalMember(Object groupIdOrPath, long userId) {
try {
return (Optional.ofNullable(getMember(groupIdOrPath, userId, false)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Gets a group team member, optionally including inherited member.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/members/all/:user_id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param userId the user ID of the member
* @param includeInherited if true will the member even if inherited thru an ancestor group
* @return the member specified by the project ID/user ID pair
* @throws GitLabApiException if any exception occurs
*/
public Member getMember(Object groupIdOrPath, Long userId, Boolean includeInherited) throws GitLabApiException {
Response response;
if (includeInherited) {
response =
get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "members", "all", userId);
} else {
response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "members", userId);
}
return (response.readEntity(Member.class));
}
/**
* Gets a group team member, optionally including inherited member.
*