forked from gitlab4j/gitlab4j-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectApi.java
4057 lines (3757 loc) · 204 KB
/
ProjectApi.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
/*
* The MIT License (MIT)
*
* Copyright (c) 2017 Greg Messner <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.gitlab4j.api;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Map;
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.AccessLevel;
import org.gitlab4j.api.models.AccessRequest;
import org.gitlab4j.api.models.ApprovalRule;
import org.gitlab4j.api.models.ApprovalRuleParams;
import org.gitlab4j.api.models.AuditEvent;
import org.gitlab4j.api.models.Badge;
import org.gitlab4j.api.models.CustomAttribute;
import org.gitlab4j.api.models.Event;
import org.gitlab4j.api.models.FileUpload;
import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.Iteration;
import org.gitlab4j.api.models.IterationFilter;
import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Namespace;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProjectAccessToken;
import org.gitlab4j.api.models.ProjectApprovalsConfig;
import org.gitlab4j.api.models.ProjectFetches;
import org.gitlab4j.api.models.ProjectFilter;
import org.gitlab4j.api.models.ProjectGroupsFilter;
import org.gitlab4j.api.models.ProjectGroup;
import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProjectUser;
import org.gitlab4j.api.models.PushRules;
import org.gitlab4j.api.models.RemoteMirror;
import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.Variable;
import org.gitlab4j.api.models.Visibility;
import org.gitlab4j.api.utils.ISO8601;
/**
* This class provides an entry point to all the GitLab API project calls.
*
* @see <a href="https://docs.gitlab.com/ce/api/projects.html">Projects API at GitLab</a>
* @see <a href="https://docs.gitlab.com/ce/api/project_statistics.html">Project statistics API</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">Group and project access requests API</a>
* @see <a href="https://docs.gitlab.com/ee/api/project_badges.html">Project badges API</a>
* @see <a href="https://docs.gitlab.com/ce/api/merge_request_approvals.html">Merge request approvals API (Project-level) at GitLab</a>
* @see <a href="https://docs.gitlab.com/ce/api/audit_events.html#retrieve-all-project-audit-events">Project audit events API</a>
* @see <a href="https://docs.gitlab.com/ce/api/custom_attributes.html">Custom Attributes API</a>
* @see <a href="https://docs.gitlab.com/ce/api/remote_mirrors.html">Project remote mirrors API</a>
*/
public class ProjectApi extends AbstractApi implements Constants {
public ProjectApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Get the project fetch statistics for the last 30 days. Retrieving the statistics requires
* write access to the repository. Currently only HTTP fetches statistics are returned.
* Fetches statistics includes both clones and pulls count and are HTTP only,
* SSH fetches are not included.
*
* <pre><code>GitLab Endpoint: GET /project/:id/statistics</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
* @return a ProjectFetches instance with the project fetch statistics for the last 30 days
* @throws GitLabApiException if any exception occurs during execution
*/
public ProjectFetches getProjectStatistics(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "statistics");
return (response.readEntity(ProjectFetches.class));
}
/**
* Get an Optional instance with the value for the project fetch statistics for the last 30 days.
*
* <pre><code>GitLab Endpoint: GET /project/:id/statistics</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
* @return an Optional instance with the value for the project fetch statistics for the last 30 day
*/
public Optional<ProjectFetches> getOptionalProjectStatistics(Object projectIdOrPath) {
try {
return (Optional.ofNullable(getProjectStatistics(projectIdOrPath)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* <p>Get a list of projects accessible by the authenticated user.</p>
*
* <strong>WARNING:</strong> Do not use this method to fetch projects from https://gitlab.com,
* gitlab.com has many 100,000's of public projects and it will take hours to fetch all of them.
* Instead use {@link #getProjects(int itemsPerPage)} which will return a Pager of Project instances.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @return a list of projects accessible by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects() throws GitLabApiException {
String url = this.gitLabApi.getGitLabServerUrl();
if (url.startsWith("https://gitlab.com")) {
GitLabApi.getLogger().warning("Fetching all projects from " + url +
" may take many hours to complete, use Pager<Project> getProjects(int) instead.");
}
return (getProjects(getDefaultPerPage()).all());
}
/**
* Get a list of projects accessible by the authenticated user and in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of projects accessible by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects");
return (response.readEntity(new GenericType<List<Project>>() { }));
}
/**
* Get a Pager instance of projects accessible by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager instance of projects accessible by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getProjects(int itemsPerPage) throws GitLabApiException {
return (new Pager<Project>(this, Project.class, itemsPerPage, null, "projects"));
}
/**
* Get a Stream of projects accessible by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @return a Stream of projects accessible by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Stream<Project> getProjectsStream() throws GitLabApiException {
return (getProjects(getDefaultPerPage()).stream());
}
/**
* Get a list of projects accessible by the authenticated user and matching the supplied filter parameters.
* All filter parameters are optional.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param archived limit by archived status
* @param visibility limit by visibility public, internal, or private
* @param orderBy return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields, default is created_at
* @param sort return projects sorted in asc or desc order. Default is desc
* @param search return list of projects matching the search criteria
* @param simple return only the ID, URL, name, and path of each project
* @param owned limit by projects owned by the current user
* @param membership limit by projects that the current user is a member of
* @param starred limit by projects starred by the current user
* @param statistics include project statistics
* @return a list of projects accessible by the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
* @deprecated Will be removed in version 6.0, replaced by {@link #getProjects(Boolean, Visibility,
* Constants.ProjectOrderBy, Constants.SortOrder, String, Boolean, Boolean, Boolean, Boolean, Boolean)}
*/
@Deprecated
public List<Project> getProjects(Boolean archived, Visibility visibility, String orderBy,
String sort, String search, Boolean simple, Boolean owned, Boolean membership,
Boolean starred, Boolean statistics) throws GitLabApiException {
ProjectOrderBy projectOrderBy = ProjectOrderBy.valueOf(orderBy);
SortOrder sortOrder = SortOrder.valueOf(sort);
return (getProjects(archived, visibility, projectOrderBy, sortOrder, search, simple,
owned, membership, starred, statistics, getDefaultPerPage()).all());
}
/**
* Get a list of projects accessible by the authenticated user and matching the supplied filter parameters.
* All filter parameters are optional.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param archived limit by archived status
* @param visibility limit by visibility public, internal, or private
* @param orderBy return projects ordered by ID, NAME, PATH, CREATED_AT, UPDATED_AT, or
* LAST_ACTIVITY_AT fields, default is CREATED_AT
* @param sort return projects sorted in asc or desc order. Default is desc
* @param search return list of projects matching the search criteria
* @param simple return only the ID, URL, name, and path of each project
* @param owned limit by projects owned by the current user
* @param membership limit by projects that the current user is a member of
* @param starred limit by projects starred by the current user
* @param statistics include project statistics
* @return a list of projects accessible by the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(Boolean archived, Visibility visibility, ProjectOrderBy orderBy,
SortOrder sort, String search, Boolean simple, Boolean owned, Boolean membership,
Boolean starred, Boolean statistics) throws GitLabApiException {
return (getProjects(archived, visibility, orderBy, sort, search, simple,
owned, membership, starred, statistics, getDefaultPerPage()).all());
}
/**
* Get a list of projects accessible by the authenticated user and matching the supplied filter parameters.
* All filter parameters are optional.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param archived limit by archived status
* @param visibility limit by visibility public, internal, or private
* @param orderBy return projects ordered by ID, NAME, PATH, CREATED_AT, UPDATED_AT, or
* LAST_ACTIVITY_AT fields, default is CREATED_AT
* @param sort return projects sorted in asc or desc order. Default is desc
* @param search return list of projects matching the search criteria
* @param simple return only the ID, URL, name, and path of each project
* @param owned limit by projects owned by the current user
* @param membership limit by projects that the current user is a member of
* @param starred limit by projects starred by the current user
* @param statistics include project statistics
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of projects accessible by the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(Boolean archived, Visibility visibility, ProjectOrderBy orderBy,
SortOrder sort, String search, Boolean simple, Boolean owned, Boolean membership,
Boolean starred, Boolean statistics, int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("archived", archived)
.withParam("visibility", visibility)
.withParam("order_by", orderBy)
.withParam("sort", sort)
.withParam("search", search)
.withParam("simple", simple)
.withParam("owned", owned)
.withParam("membership", membership)
.withParam("starred", starred)
.withParam("statistics", statistics)
.withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}
/**
* Get a Pager of projects accessible by the authenticated user and matching the supplied filter parameters.
* All filter parameters are optional.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param archived limit by archived status
* @param visibility limit by visibility public, internal, or private
* @param orderBy return projects ordered by ID, NAME, PATH, CREATED_AT, UPDATED_AT, or
* LAST_ACTIVITY_AT fields, default is CREATED_AT
* @param sort return projects sorted in asc or desc order. Default is desc
* @param search return list of projects matching the search criteria
* @param simple return only the ID, URL, name, and path of each project
* @param owned limit by projects owned by the current user
* @param membership limit by projects that the current user is a member of
* @param starred limit by projects starred by the current user
* @param statistics include project statistics
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of projects accessible by the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getProjects(Boolean archived, Visibility visibility, ProjectOrderBy orderBy,
SortOrder sort, String search, Boolean simple, Boolean owned, Boolean membership,
Boolean starred, Boolean statistics, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("archived", archived)
.withParam("visibility", visibility)
.withParam("order_by", orderBy)
.withParam("sort", sort)
.withParam("search", search)
.withParam("simple", simple)
.withParam("owned", owned)
.withParam("membership", membership)
.withParam("starred", starred)
.withParam("statistics", statistics);
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "projects"));
}
/**
* Get a list of projects accessible by the authenticated user that match the provided search string.
*
* <pre><code>GitLab Endpoint: GET /projects?search=search</code></pre>
*
* @param search the project name search criteria
* @return a list of projects accessible by the authenticated user that match the provided search string
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(String search) throws GitLabApiException {
return (getProjects(search, getDefaultPerPage()).all());
}
/**
* Get a list of projects accessible by the authenticated user that match the provided search string.
*
* <pre><code>GitLab Endpoint: GET /projects?search=search</code></pre>
*
* @param search the project name search criteria
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of projects accessible by the authenticated user that match the provided search string
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(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(), "projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}
/**
* Get a Pager of projects accessible by the authenticated user that match the provided search string.
*
* <pre><code>GitLab Endpoint: GET /projects?search=search</code></pre>
*
* @param search the project name search criteria
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of projects accessible by the authenticated user that match the provided search string
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getProjects(String search, int itemsPerPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("search", search);
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "projects"));
}
/**
* Get a Stream of projects accessible by the authenticated user that match the provided search string.
*
* <pre><code>GitLab Endpoint: GET /projects?search=search</code></pre>
*
* @param search the project name search criteria
* @return a Stream of projects accessible by the authenticated user that match the provided search string
* @throws GitLabApiException if any exception occurs
*/
public Stream<Project> getProjectsStream(String search) throws GitLabApiException {
return (getProjects(search, getDefaultPerPage()).stream());
}
/**
* Get a list of projects that the authenticated user is a member of.
*
* <pre><code>GitLab Endpoint: GET /projects?membership=true</code></pre>
*
* @return a list of projects that the authenticated user is a member of
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getMemberProjects() throws GitLabApiException {
return (getMemberProjects(getDefaultPerPage()).all());
}
/**
* Get a list of projects that the authenticated user is a member of in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /projects?membership=true</code></pre>
*
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of projects that the authenticated user is a member of
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getMemberProjects(int page, int perPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("membership", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}
/**
* Get a Pager of projects that the authenticated user is a member of.
*
* <pre><code>GitLab Endpoint: GET /projects?membership=true</code></pre>
*
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager o Project instances that the authenticated user is a member of
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getMemberProjects(int itemsPerPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("membership", true);
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "projects"));
}
/**
* Get a Stream of projects that the authenticated user is a member of.
*
* <pre><code>GitLab Endpoint: GET /projects?membership=true</code></pre>
*
* @return a list of projects that the authenticated user is a member of
* @throws GitLabApiException if any exception occurs
*/
public Stream<Project> getMemberProjectsStream() throws GitLabApiException {
return (getMemberProjects(getDefaultPerPage()).stream());
}
/**
* Get a list of projects owned by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /projects?owned=true</code></pre>
*
* @return a list of projects owned by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getOwnedProjects() throws GitLabApiException {
return (getOwnedProjects(getDefaultPerPage()).all());
}
/**
* Get a list of projects owned by the authenticated user in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /projects?owned=true</code></pre>
*
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of projects owned by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getOwnedProjects(int page, int perPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("owned", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}
/**
* Get a Pager of projects owned by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /projects?owned=true</code></pre>
*
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a list of projects owned by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getOwnedProjects(int itemsPerPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("owned", true);
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "projects"));
}
/**
* Get a Stream of projects owned by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /projects?owned=true</code></pre>
*
* @return a Stream of projects owned by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Stream<Project> getOwnedProjectsStream() throws GitLabApiException {
return (getOwnedProjects(getDefaultPerPage()).stream());
}
/**
* Get a list of projects starred by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /projects?starred=true</code></pre>
*
* @return a list of projects starred by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getStarredProjects() throws GitLabApiException {
return (getStarredProjects(getDefaultPerPage()).all());
}
/**
* Get a list of projects starred by the authenticated user in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /projects?starred=true</code></pre>
*
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of projects starred by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getStarredProjects(int page, int perPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("starred", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}
/**
* Get a Pager of projects starred by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /projects?starred=true</code></pre>
*
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of projects starred by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getStarredProjects(int itemsPerPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("starred", true).withParam(PER_PAGE_PARAM, getDefaultPerPage());
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "projects"));
}
/**
* Get a Stream of projects starred by the authenticated user.
*
* <pre><code>GitLab Endpoint: GET /projects?starred=true</code></pre>
*
* @return a Stream of projects starred by the authenticated user
* @throws GitLabApiException if any exception occurs
*/
public Stream<Project> getStarredProjectsStream() throws GitLabApiException {
return (getStarredProjects(getDefaultPerPage()).stream());
}
/**
* Get a list of all visible projects across GitLab for the authenticated user using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param filter the ProjectFilter instance holding the filter values for the query
* @return a list of all visible projects across GitLab for the authenticated use
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(ProjectFilter filter) throws GitLabApiException {
return (getProjects(filter, getDefaultPerPage()).all());
}
/**
* Get a list of all visible projects across GitLab for the authenticated user in the specified page range
* using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param filter the ProjectFilter instance holding the filter values for the query
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of all visible projects across GitLab for the authenticated use
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(ProjectFilter filter, int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams(page, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}
/**
* Get a Pager of all visible projects across GitLab for the authenticated user using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param filter the ProjectFilter instance holding the filter values for the query
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of all visible projects across GitLab for the authenticated use
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getProjects(ProjectFilter filter, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "projects"));
}
/**
* Get a Stream of all visible projects across GitLab for the authenticated user using the provided filter.
*
* <pre><code>GitLab Endpoint: GET /projects</code></pre>
*
* @param filter the ProjectFilter instance holding the filter values for the query
* @return a Stream of all visible projects across GitLab for the authenticated use
* @throws GitLabApiException if any exception occurs
*/
public Stream<Project> getProjectsStream(ProjectFilter filter) throws GitLabApiException {
return (getProjects(filter, getDefaultPerPage()).stream());
}
/**
* Get a list of visible projects owned by the given user.
*
* <pre><code>GitLab Endpoint: GET /users/:user_id/projects</code></pre>
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @return a list of visible projects owned by the given user
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getUserProjects(Object userIdOrUsername, ProjectFilter filter) throws GitLabApiException {
return (getUserProjects(userIdOrUsername, filter, getDefaultPerPage()).all());
}
/**
* Get a list of visible projects owned by the given user in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /users/:user_id/projects</code></pre>
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of visible projects owned by the given user
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getUserProjects(Object userIdOrUsername, ProjectFilter filter, int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams(page, perPage);
Response response = get(Response.Status.OK, formData.asMap(),
"users", getUserIdOrUsername(userIdOrUsername), "projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}
/**
* Get a Pager of visible projects owned by the given user.
*
* <pre><code>GitLab Endpoint: GET /users/:user_id/projects</code></pre>
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of visible projects owned by the given user
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getUserProjects(Object userIdOrUsername, ProjectFilter filter, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(),
"users", getUserIdOrUsername(userIdOrUsername), "projects"));
}
/**
* Get a Stream of visible projects owned by the given user.
*
* <pre><code>GitLab Endpoint: GET /users/:user_id/projects</code></pre>
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @return a Stream of visible projects owned by the given user
* @throws GitLabApiException if any exception occurs
*/
public Stream<Project> getUserProjectsStream(Object userIdOrUsername, ProjectFilter filter) throws GitLabApiException {
return (getUserProjects(userIdOrUsername, filter, getDefaultPerPage()).stream());
}
/**
* Get a specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @return the specified project
* @throws GitLabApiException if any exception occurs
*/
public Project getProject(Object projectIdOrPath) throws GitLabApiException {
return (getProject(projectIdOrPath, null, null, null));
}
/**
* Get an Optional instance with the value for the specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @return an Optional instance with the specified project as a value
*/
public Optional<Project> getOptionalProject(Object projectIdOrPath) {
try {
return (Optional.ofNullable(getProject(projectIdOrPath, null, null, null)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Get a specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param includeStatistics include project statistics
* @return the specified project
* @throws GitLabApiException if any exception occurs
*/
public Project getProject(Object projectIdOrPath, Boolean includeStatistics) throws GitLabApiException {
return (getProject(projectIdOrPath, includeStatistics, null, null));
}
/**
* Get an Optional instance with the value for the specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param includeStatistics include project statistics
* @return an Optional instance with the specified project as a value
*/
public Optional<Project> getOptionalProject(Object projectIdOrPath, Boolean includeStatistics) {
try {
return (Optional.ofNullable(getProject(projectIdOrPath, includeStatistics, null, null)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Get a specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param includeStatistics include project statistics
* @param includeLicense include project license data
* @param withCustomAttributes include custom attributes in response (admins only)
* @return the specified project
* @throws GitLabApiException if any exception occurs
*/
public Project getProject(Object projectIdOrPath, Boolean includeStatistics,
Boolean includeLicense, Boolean withCustomAttributes) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("statistics", includeStatistics)
.withParam("license", includeLicense)
.withParam("with_custom_attributes", withCustomAttributes);
Response response = get(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath));
return (response.readEntity(Project.class));
}
/**
* Get an Optional instance with the value for the specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param includeStatistics include project statistics
* @param includeLicense include project license data
* @param withCustomAttributes include custom attributes in response (admins only)
* @return an Optional instance with the specified project as a value
*/
public Optional<Project> getOptionalProject(Object projectIdOrPath, Boolean includeStatistics,
Boolean includeLicense, Boolean withCustomAttributes) {
try {
return (Optional.ofNullable(getProject(projectIdOrPath,
includeStatistics, includeLicense, withCustomAttributes)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Get a specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param namespace the name of the project namespace or group
* @param project the name of the project to get
* @return the specified project
* @throws GitLabApiException if any exception occurs
*/
public Project getProject(String namespace, String project) throws GitLabApiException {
if (namespace == null) {
throw new RuntimeException("namespace cannot be null");
}
if (project == null) {
throw new RuntimeException("project cannot be null");
}
String projectPath = null;
try {
projectPath = URLEncoder.encode(namespace + "/" + project, "UTF-8");
} catch (UnsupportedEncodingException uee) {
throw (new GitLabApiException(uee));
}
Response response = get(Response.Status.OK, null, "projects", projectPath);
return (response.readEntity(Project.class));
}
/**
* Get an Optional instance with the value for the specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param namespace the name of the project namespace or group
* @param project the name of the project
* @return an Optional instance with the specified project as a value
*/
public Optional<Project> getOptionalProject(String namespace, String project) {
try {
return (Optional.ofNullable(getProject(namespace, project)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Get a specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param namespace the name of the project namespace or group
* @param project the name of the project to get
* @param includeStatistics include project statistics
* @return the specified project
* @throws GitLabApiException if any exception occurs
*/
public Project getProject(String namespace, String project, Boolean includeStatistics) throws GitLabApiException {
if (namespace == null) {
throw new RuntimeException("namespace cannot be null");
}
if (project == null) {
throw new RuntimeException("project cannot be null");
}
String projectPath = null;
try {
projectPath = URLEncoder.encode(namespace + "/" + project, "UTF-8");
} catch (UnsupportedEncodingException uee) {
throw (new GitLabApiException(uee));
}
Form formData = new GitLabApiForm().withParam("statistics", includeStatistics);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectPath);
return (response.readEntity(Project.class));
}
/**
* Get an Optional instance with the value for the specific project, which is owned by the authentication user.
*
* <pre><code>GitLab Endpoint: GET /projects/:id</code></pre>
*
* @param namespace the name of the project namespace or group
* @param project the name of the project
* @param includeStatistics include project statistics
* @return an Optional instance with the specified project as a value
*/
public Optional<Project> getOptionalProject(String namespace, String project, Boolean includeStatistics) {
try {
return (Optional.ofNullable(getProject(namespace, project, includeStatistics)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/**
* Create a new project belonging to the namespace ID. A namespace ID is either a user or group ID.
*
* @param namespaceId the namespace ID to create the project under
* @param projectName the name of the project top create
* @return the created project
* @throws GitLabApiException if any exception occurs
*/
public Project createProject(Long namespaceId, String projectName) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("namespace_id", namespaceId).withParam("name", projectName, true);
Response response = post(Response.Status.CREATED, formData, "projects");
return (response.readEntity(Project.class));
}
/**
* Create a new project belonging to the namespace ID and project configuration. A namespace ID is either a user or group ID.
*
* @param namespaceId the namespace ID to create the project under
* @param project the Project instance holding the new project configuration
* @return the created project
* @throws GitLabApiException if any exception occurs
*/
public Project createProject(Long namespaceId, Project project) throws GitLabApiException {
if (project == null) {
throw new RuntimeException("Project instance cannot be null.");
}
Namespace namespace = new Namespace().withId(namespaceId);
project.setNamespace(namespace);
return (createProject(project));
}
/**
* Create a new project with the current user's namespace.
*
* @param projectName the name of the project top create
* @return the created project
* @throws GitLabApiException if any exception occurs
*/
public Project createProject(String projectName) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("name", projectName, true);
Response response = post(Response.Status.CREATED, formData, "projects");
return (response.readEntity(Project.class));
}
/**
* Creates a new project owned by the authenticated user.
*
* @param name the name of the project top create. Equals path if not provided.
* @param path repository name for new project. Generated based on name if not provided (generated lowercased with dashes).
* @return the created project
* @throws GitLabApiException if any exception occurs
*/
public Project createProject(String name, String path) throws GitLabApiException {
if ((name == null || name.trim().isEmpty()) && (path == null || path.trim().isEmpty())) {
throw new RuntimeException("Either name or path must be specified.");
}
GitLabApiForm formData = new GitLabApiForm().withParam("name", name).withParam("path", path);
Response response = post(Response.Status.CREATED, formData, "projects");
return (response.readEntity(Project.class));
}
/**
* Creates new project owned by the current user.
*
* @param project the Project instance with the configuration for the new project
* @return a Project instance with the newly created project info
* @throws GitLabApiException if any exception occurs
*/
public Project createProject(Project project) throws GitLabApiException {
return (createProject(project, null));
}
/**
* Creates new project owned by the current user. The following properties on the Project instance
* are utilized in the creation of the project:
*
* name (name or path are required) - new project name
* path (name or path are required) - new project path
* defaultBranch (optional) - master by default
* description (optional) - short project description
* visibility (optional) - Limit by visibility public, internal, or private
* visibilityLevel (optional)
* issuesEnabled (optional) - Enable issues for this project
* mergeMethod (optional) - Set the merge method used
* mergeRequestsEnabled (optional) - Enable merge requests for this project
* wikiEnabled (optional) - Enable wiki for this project
* snippetsEnabled (optional) - Enable snippets for this project
* jobsEnabled (optional) - Enable jobs for this project
* containerRegistryEnabled (optional) - Enable container registry for this project
* sharedRunnersEnabled (optional) - Enable shared runners for this project
* publicJobs (optional) - If true, jobs can be viewed by non-project-members
* onlyAllowMergeIfPipelineSucceeds (optional) - Set whether merge requests can only be merged with successful jobs
* onlyAllowMergeIfAllDiscussionsAreResolved (optional) - Set whether merge requests can only be merged when all the discussions are resolved
* lfsEnabled (optional) - Enable LFS
* requestAccessEnabled (optional) - Allow users to request member access
* repositoryStorage (optional) - Which storage shard the repository is on. Available only to admins
* approvalsBeforeMerge (optional) - How many approvers should approve merge request by default
* printingMergeRequestLinkEnabled (optional) - Show link to create/view merge request when pushing from the command line
* resolveOutdatedDiffDiscussions (optional) - Automatically resolve merge request diffs discussions on lines changed with a push
* initialize_with_readme (optional) - Initialize project with README file
* packagesEnabled (optional) - Enable or disable mvn packages repository feature
* buildGitStrategy (optional) - set the build git strategy
* buildCoverageRegex (optional) - set build coverage regex
* ciConfigPath (optional) - Set path to CI configuration file
* squashOption (optional) - set squash option for merge requests
*
* @param project the Project instance with the configuration for the new project
* @param importUrl the URL to import the repository from
* @return a Project instance with the newly created project info
* @throws GitLabApiException if any exception occurs
*/
public Project createProject(Project project, String importUrl) throws GitLabApiException {
if (project == null) {
return (null);
}
String name = project.getName();
String path = project.getPath();