77import java .nio .file .StandardCopyOption ;
88import java .util .List ;
99import java .util .Optional ;
10+ import java .util .stream .Stream ;
1011
1112import javax .ws .rs .core .Form ;
1213import javax .ws .rs .core .GenericType ;
@@ -40,9 +41,7 @@ public RepositoryApi(GitLabApi gitLabApi) {
4041 * @throws GitLabApiException if any exception occurs
4142 */
4243 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 ());
4645 }
4746
4847 /**
@@ -78,6 +77,19 @@ public Pager<Branch> getBranches(Object projectIdOrPath, int itemsPerPage) throw
7877 getProjectIdOrPath (projectIdOrPath ), "repository" , "branches" ));
7978 }
8079
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+
8193 /**
8294 * Get a single project repository branch.
8395 *
@@ -192,6 +204,7 @@ public Branch unprotectBranch(Object projectIdOrPath, String branchName) throws
192204 * @throws GitLabApiException if any exception occurs
193205 * @deprecated Replaced by TagsApi.getTags(Object)
194206 */
207+ @ Deprecated
195208 public List <Tag > getTags (Object projectIdOrPath ) throws GitLabApiException {
196209 Response response = get (Response .Status .OK , getDefaultPerPageParam (), "projects" ,
197210 getProjectIdOrPath (projectIdOrPath ), "repository" , "tags" );
@@ -210,6 +223,7 @@ public List<Tag> getTags(Object projectIdOrPath) throws GitLabApiException {
210223 * @throws GitLabApiException if any exception occurs
211224 * @deprecated Replaced by TagsApi.getTags(Object, int, int)
212225 */
226+ @ Deprecated
213227 public List <Tag > getTags (Object projectIdOrPath , int page , int perPage ) throws GitLabApiException {
214228 Response response = get (Response .Status .OK , getPageQueryParams (page , perPage ), "projects" ,
215229 getProjectIdOrPath (projectIdOrPath ), "repository" , "tags" );
@@ -227,6 +241,7 @@ public List<Tag> getTags(Object projectIdOrPath, int page, int perPage) throws G
227241 * @throws GitLabApiException if any exception occurs
228242 * @deprecated Replaced by TagsApi.getTags(Object, int)
229243 */
244+ @ Deprecated
230245 public Pager <Tag > getTags (Object projectIdOrPath , int itemsPerPage ) throws GitLabApiException {
231246 return (new Pager <Tag >(this , Tag .class , itemsPerPage , null , "projects" ,
232247 getProjectIdOrPath (projectIdOrPath ), "repository" , "tags" ));
@@ -332,6 +347,19 @@ public Pager<TreeItem> getTree(Object projectIdOrPath, int itemsPerPage) throws
332347 return (getTree (projectIdOrPath , "/" , "master" , false , itemsPerPage ));
333348 }
334349
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+
335363 /**
336364 * Get a list of repository files and directories in a project.
337365 *
@@ -371,6 +399,25 @@ public Pager<TreeItem> getTree(Object projectIdOrPath, String filePath, String r
371399 return (getTree (projectIdOrPath , filePath , refName , false , itemsPerPage ));
372400 }
373401
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+
374421 /**
375422 * Get a list of repository files and directories in a project.
376423 *
@@ -389,14 +436,7 @@ public Pager<TreeItem> getTree(Object projectIdOrPath, String filePath, String r
389436 * @throws GitLabApiException if any exception occurs
390437 */
391438 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 ());
400440 }
401441
402442 /**
@@ -427,6 +467,27 @@ public Pager<TreeItem> getTree(Object projectIdOrPath, String filePath, String r
427467 getProjectIdOrPath (projectIdOrPath ), "repository" , "tree" ));
428468 }
429469
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+
430491 /**
431492 * Get the raw file contents for a blob by blob SHA.
432493 *
@@ -634,7 +695,7 @@ public CompareResults compare(Object projectIdOrPath, String from, String to) th
634695 * @throws GitLabApiException if any exception occurs
635696 */
636697 public List <Contributor > getContributors (Object projectIdOrPath ) throws GitLabApiException {
637- return (getContributors (projectIdOrPath , 1 , getDefaultPerPage ()));
698+ return (getContributors (projectIdOrPath , getDefaultPerPage ()). all ( ));
638699 }
639700
640701 /**
@@ -668,4 +729,17 @@ public Pager<Contributor> getContributors(Object projectIdOrPath, int itemsPerPa
668729 return new Pager <Contributor >(this , Contributor .class , itemsPerPage , null , "projects" ,
669730 getProjectIdOrPath (projectIdOrPath ), "repository" , "contributors" );
670731 }
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+ }
671745}
0 commit comments