7
7
import java .nio .file .StandardCopyOption ;
8
8
import java .util .List ;
9
9
import java .util .Optional ;
10
+ import java .util .stream .Stream ;
10
11
11
12
import javax .ws .rs .core .Form ;
12
13
import javax .ws .rs .core .GenericType ;
@@ -40,9 +41,7 @@ public RepositoryApi(GitLabApi gitLabApi) {
40
41
* @throws GitLabApiException if any exception occurs
41
42
*/
42
43
public List <Branch > getBranches (Object projectIdOrPath ) throws GitLabApiException {
43
- Response response = get (Response .Status .OK , getDefaultPerPageParam (),
44
- "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "branches" );
45
- return (response .readEntity (new GenericType <List <Branch >>() {}));
44
+ return (getBranches (projectIdOrPath , getDefaultPerPage ()).all ());
46
45
}
47
46
48
47
/**
@@ -78,6 +77,19 @@ public Pager<Branch> getBranches(Object projectIdOrPath, int itemsPerPage) throw
78
77
getProjectIdOrPath (projectIdOrPath ), "repository" , "branches" ));
79
78
}
80
79
80
+ /**
81
+ * Get a Stream of repository branches from a project, sorted by name alphabetically.
82
+ *
83
+ * GET /projects/:id/repository/branches
84
+ *
85
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
86
+ * @return a Stream of repository branches for the specified project
87
+ * @throws GitLabApiException if any exception occurs
88
+ */
89
+ public Stream <Branch > getBranchesStream (Object projectIdOrPath ) throws GitLabApiException {
90
+ return (getBranches (projectIdOrPath , getDefaultPerPage ()).stream ());
91
+ }
92
+
81
93
/**
82
94
* Get a single project repository branch.
83
95
*
@@ -192,6 +204,7 @@ public Branch unprotectBranch(Object projectIdOrPath, String branchName) throws
192
204
* @throws GitLabApiException if any exception occurs
193
205
* @deprecated Replaced by TagsApi.getTags(Object)
194
206
*/
207
+ @ Deprecated
195
208
public List <Tag > getTags (Object projectIdOrPath ) throws GitLabApiException {
196
209
Response response = get (Response .Status .OK , getDefaultPerPageParam (), "projects" ,
197
210
getProjectIdOrPath (projectIdOrPath ), "repository" , "tags" );
@@ -210,6 +223,7 @@ public List<Tag> getTags(Object projectIdOrPath) throws GitLabApiException {
210
223
* @throws GitLabApiException if any exception occurs
211
224
* @deprecated Replaced by TagsApi.getTags(Object, int, int)
212
225
*/
226
+ @ Deprecated
213
227
public List <Tag > getTags (Object projectIdOrPath , int page , int perPage ) throws GitLabApiException {
214
228
Response response = get (Response .Status .OK , getPageQueryParams (page , perPage ), "projects" ,
215
229
getProjectIdOrPath (projectIdOrPath ), "repository" , "tags" );
@@ -227,6 +241,7 @@ public List<Tag> getTags(Object projectIdOrPath, int page, int perPage) throws G
227
241
* @throws GitLabApiException if any exception occurs
228
242
* @deprecated Replaced by TagsApi.getTags(Object, int)
229
243
*/
244
+ @ Deprecated
230
245
public Pager <Tag > getTags (Object projectIdOrPath , int itemsPerPage ) throws GitLabApiException {
231
246
return (new Pager <Tag >(this , Tag .class , itemsPerPage , null , "projects" ,
232
247
getProjectIdOrPath (projectIdOrPath ), "repository" , "tags" ));
@@ -332,6 +347,19 @@ public Pager<TreeItem> getTree(Object projectIdOrPath, int itemsPerPage) throws
332
347
return (getTree (projectIdOrPath , "/" , "master" , false , itemsPerPage ));
333
348
}
334
349
350
+ /**
351
+ * Get a list of repository files and directories in a project.
352
+ *
353
+ * GET /projects/:id/repository/tree
354
+ *
355
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
356
+ * @return a Stream containing a tree with the root directories and files of a project
357
+ * @throws GitLabApiException if any exception occurs
358
+ */
359
+ public Stream <TreeItem > getTreeStream (Object projectIdOrPath ) throws GitLabApiException {
360
+ return (getTreeStream (projectIdOrPath , "/" , "master" ));
361
+ }
362
+
335
363
/**
336
364
* Get a list of repository files and directories in a project.
337
365
*
@@ -371,6 +399,25 @@ public Pager<TreeItem> getTree(Object projectIdOrPath, String filePath, String r
371
399
return (getTree (projectIdOrPath , filePath , refName , false , itemsPerPage ));
372
400
}
373
401
402
+ /**
403
+ * Get a Stream of repository files and directories in a project.
404
+ *
405
+ * GET /projects/:id/repository/tree
406
+ *
407
+ * id (required) - The ID of a project
408
+ * path (optional) - The path inside repository. Used to get content of subdirectories
409
+ * ref_name (optional) - The name of a repository branch or tag or if not given the default branch
410
+ *
411
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
412
+ * @param filePath the path inside repository, used to get content of subdirectories
413
+ * @param refName the name of a repository branch or tag or if not given the default branch
414
+ * @return a Stream containing a tree with the directories and files of a project
415
+ * @throws GitLabApiException if any exception occurs
416
+ */
417
+ public Stream <TreeItem > getTreeStream (Object projectIdOrPath , String filePath , String refName ) throws GitLabApiException {
418
+ return (getTreeStream (projectIdOrPath , filePath , refName , false ));
419
+ }
420
+
374
421
/**
375
422
* Get a list of repository files and directories in a project.
376
423
*
@@ -389,14 +436,7 @@ public Pager<TreeItem> getTree(Object projectIdOrPath, String filePath, String r
389
436
* @throws GitLabApiException if any exception occurs
390
437
*/
391
438
public List <TreeItem > getTree (Object projectIdOrPath , String filePath , String refName , Boolean recursive ) throws GitLabApiException {
392
- Form formData = new GitLabApiForm ()
393
- .withParam ("id" , getProjectIdOrPath (projectIdOrPath ), true )
394
- .withParam ("path" , filePath , false )
395
- .withParam (isApiVersion (ApiVersion .V3 ) ? "ref_name" : "ref" , refName , false )
396
- .withParam ("recursive" , recursive , false )
397
- .withParam (PER_PAGE_PARAM , getDefaultPerPage ());
398
- Response response = get (Response .Status .OK , formData .asMap (), "projects" , getProjectIdOrPath (projectIdOrPath ), "repository" , "tree" );
399
- return (response .readEntity (new GenericType <List <TreeItem >>() {}));
439
+ return (getTree (projectIdOrPath , filePath , refName , recursive , getDefaultPerPage ()).all ());
400
440
}
401
441
402
442
/**
@@ -427,6 +467,27 @@ public Pager<TreeItem> getTree(Object projectIdOrPath, String filePath, String r
427
467
getProjectIdOrPath (projectIdOrPath ), "repository" , "tree" ));
428
468
}
429
469
470
+ /**
471
+ * Get a Stream of repository files and directories in a project.
472
+ *
473
+ * GET /projects/:id/repository/tree
474
+ *
475
+ * id (required) - The ID of a project
476
+ * path (optional) - The path inside repository. Used to get contend of subdirectories
477
+ * ref_name (optional) - The name of a repository branch or tag or if not given the default branch
478
+ * recursive (optional) - Boolean value used to get a recursive tree (false by default)
479
+ *
480
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
481
+ * @param filePath the path inside repository, used to get content of subdirectories
482
+ * @param refName the name of a repository branch or tag or if not given the default branch
483
+ * @param recursive flag to get a recursive tree or not
484
+ * @return a Stream containing a tree with the directories and files of a project
485
+ * @throws GitLabApiException if any exception occurs
486
+ */
487
+ public Stream <TreeItem > getTreeStream (Object projectIdOrPath , String filePath , String refName , Boolean recursive ) throws GitLabApiException {
488
+ return (getTree (projectIdOrPath , filePath , refName , recursive , getDefaultPerPage ()).stream ());
489
+ }
490
+
430
491
/**
431
492
* Get the raw file contents for a blob by blob SHA.
432
493
*
@@ -634,7 +695,7 @@ public CompareResults compare(Object projectIdOrPath, String from, String to) th
634
695
* @throws GitLabApiException if any exception occurs
635
696
*/
636
697
public List <Contributor > getContributors (Object projectIdOrPath ) throws GitLabApiException {
637
- return (getContributors (projectIdOrPath , 1 , getDefaultPerPage ()));
698
+ return (getContributors (projectIdOrPath , getDefaultPerPage ()). all ( ));
638
699
}
639
700
640
701
/**
@@ -668,4 +729,17 @@ public Pager<Contributor> getContributors(Object projectIdOrPath, int itemsPerPa
668
729
return new Pager <Contributor >(this , Contributor .class , itemsPerPage , null , "projects" ,
669
730
getProjectIdOrPath (projectIdOrPath ), "repository" , "contributors" );
670
731
}
732
+
733
+ /**
734
+ * Get a list of contributors from a project.
735
+ *
736
+ * GET /projects/:id/repository/contributors
737
+ *
738
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
739
+ * @return a List containing the contributors for the specified project ID
740
+ * @throws GitLabApiException if any exception occurs
741
+ */
742
+ public Stream <Contributor > getContributorsStream (Object projectIdOrPath ) throws GitLabApiException {
743
+ return (getContributors (projectIdOrPath , getDefaultPerPage ()).stream ());
744
+ }
671
745
}
0 commit comments