Skip to content

Commit 4123ef0

Browse files
committed
Added getXxxxx() methods that return Java 8 Streams.
1 parent 00b4a68 commit 4123ef0

File tree

7 files changed

+869
-705
lines changed

7 files changed

+869
-705
lines changed

src/main/java/org/gitlab4j/api/GroupApi.java

Lines changed: 216 additions & 165 deletions
Large diffs are not rendered by default.

src/main/java/org/gitlab4j/api/IssuesApi.java

Lines changed: 174 additions & 147 deletions
Large diffs are not rendered by default.

src/main/java/org/gitlab4j/api/NotesApi.java

Lines changed: 138 additions & 109 deletions
Large diffs are not rendered by default.

src/main/java/org/gitlab4j/api/ProjectApi.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ public ProjectHook modifyHook(ProjectHook hook) throws GitLabApiException {
17941794
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
17951795
* @return a list of project's issues
17961796
* @throws GitLabApiException if any exception occurs
1797-
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Integer)}
1797+
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Object)}
17981798
*/
17991799
@Deprecated
18001800
public List<Issue> getIssues(Object projectIdOrPath) throws GitLabApiException {
@@ -1811,7 +1811,7 @@ public List<Issue> getIssues(Object projectIdOrPath) throws GitLabApiException {
18111811
* @param perPage the number of issues per page
18121812
* @return the list of issues in the specified range
18131813
* @throws GitLabApiException if any exception occurs
1814-
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Integer, int, int)}
1814+
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Object, int, int)}
18151815
*/
18161816
@Deprecated
18171817
public List<Issue> getIssues(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
@@ -1828,7 +1828,7 @@ public List<Issue> getIssues(Object projectIdOrPath, int page, int perPage) thro
18281828
* @param itemsPerPage the number of issues per page
18291829
* @return the list of issues in the specified range
18301830
* @throws GitLabApiException if any exception occurs
1831-
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Integer, int)}
1831+
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Object, int)}
18321832
*/
18331833
@Deprecated
18341834
public Pager<Issue> getIssues(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
@@ -1843,7 +1843,7 @@ public Pager<Issue> getIssues(Object projectIdOrPath, int itemsPerPage) throws G
18431843
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
18441844
* @return a Stream of the project's issues
18451845
* @throws GitLabApiException if any exception occurs
1846-
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Integer)}
1846+
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Object)}
18471847
*/
18481848
@Deprecated
18491849
public Stream<Issue> getIssuesStream(Object projectIdOrPath) throws GitLabApiException {
@@ -1859,7 +1859,7 @@ public Stream<Issue> getIssuesStream(Object projectIdOrPath) throws GitLabApiExc
18591859
* @param issueId the internal ID of a project's issue
18601860
* @return the specified Issue instance
18611861
* @throws GitLabApiException if any exception occurs
1862-
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssue(Integer, Integer)}
1862+
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssue(Object, Integer)}
18631863
*/
18641864
@Deprecated
18651865
public Issue getIssue(Object projectIdOrPath, Integer issueId) throws GitLabApiException {
@@ -1875,7 +1875,7 @@ public Issue getIssue(Object projectIdOrPath, Integer issueId) throws GitLabApiE
18751875
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
18761876
* @param issueId the internal ID of a project's issue
18771877
* @throws GitLabApiException if any exception occurs
1878-
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#deleteIssue(Integer, Integer)}
1878+
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#deleteIssue(Object, Integer)}
18791879
*/
18801880
@Deprecated
18811881
public void deleteIssue(Object projectIdOrPath, Integer issueId) throws GitLabApiException {
@@ -2398,8 +2398,8 @@ public Project transferProject(Object projectIdOrPath, String namespace) throws
23982398
* @return the updated Project instance
23992399
* @throws GitLabApiException if any exception occurs
24002400
*/
2401-
public Project setProjectAvatar(Object projectIdOrPath, File fileToUpload) throws GitLabApiException {
2402-
return (setProjectAvatar(projectIdOrPath, fileToUpload, null));
2401+
public Project setProjectAvatar(Object projectIdOrPath, File avatarFile) throws GitLabApiException {
2402+
return (setProjectAvatar(projectIdOrPath, avatarFile, null));
24032403
}
24042404

24052405
/**

src/main/java/org/gitlab4j/api/RepositoryApi.java

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.nio.file.StandardCopyOption;
88
import java.util.List;
99
import java.util.Optional;
10+
import java.util.stream.Stream;
1011

1112
import javax.ws.rs.core.Form;
1213
import 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
}

src/main/java/org/gitlab4j/api/TagsApi.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.IOException;
55
import java.util.List;
66
import java.util.Optional;
7+
import java.util.stream.Stream;
78

89
import javax.ws.rs.core.Form;
910
import javax.ws.rs.core.GenericType;
@@ -28,22 +29,20 @@ public TagsApi(GitLabApi gitLabApi) {
2829
/**
2930
* Get a list of repository tags from a project, sorted by name in reverse alphabetical order.
3031
*
31-
* GET /projects/:id/repository/tags
32+
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tags</code></pre>
3233
*
3334
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
3435
* @return the list of tags for the specified project ID
3536
* @throws GitLabApiException if any exception occurs
3637
*/
3738
public List<Tag> getTags(Object projectIdOrPath) throws GitLabApiException {
38-
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
39-
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags");
40-
return (response.readEntity(new GenericType<List<Tag>>() { }));
39+
return (getTags(projectIdOrPath, getDefaultPerPage()).all());
4140
}
4241

4342
/**
4443
* Get a list of repository tags from a project, sorted by name in reverse alphabetical order and in the specified page range.
4544
*
46-
* GET /projects/:id/repository/tags
45+
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tags</code></pre>
4746
*
4847
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
4948
* @param page the page to get
@@ -60,7 +59,7 @@ public List<Tag> getTags(Object projectIdOrPath, int page, int perPage) throws G
6059
/**
6160
* Get a list of repository tags from a project, sorted by name in reverse alphabetical order.
6261
*
63-
* GET /projects/:id/repository/tags
62+
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tags</code></pre>
6463
*
6564
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
6665
* @param itemsPerPage the number of Project instances that will be fetched per page
@@ -71,10 +70,23 @@ public Pager<Tag> getTags(Object projectIdOrPath, int itemsPerPage) throws GitLa
7170
return (new Pager<Tag>(this, Tag.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags"));
7271
}
7372

73+
/**
74+
* Get a Stream of repository tags from a project, sorted by name in reverse alphabetical order.
75+
*
76+
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tags</code></pre>
77+
*
78+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
79+
* @return a Stream of tags for the specified project ID
80+
* @throws GitLabApiException if any exception occurs
81+
*/
82+
public Stream<Tag> getTagsStream(Object projectIdOrPath) throws GitLabApiException {
83+
return (getTags(projectIdOrPath, getDefaultPerPage()).stream());
84+
}
85+
7486
/**
7587
* Get a specific repository tag determined by its name.
7688
*
77-
* GET /projects/:id/repository/tags/:tagName
89+
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tags/:tagName</code></pre>
7890
*
7991
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
8092
* @param tagName the name of the tag to fetch the info for
@@ -89,7 +101,7 @@ public Tag getTag(Object projectIdOrPath, String tagName) throws GitLabApiExcept
89101
/**
90102
* Get an Optional instance holding a Tag instance of a specific repository tag determined by its name.
91103
*
92-
* GET /projects/:id/repository/tags/:tagName
104+
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tags/:tagName</code></pre>
93105
*
94106
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
95107
* @param tagName the name of the tag to fetch the info for
@@ -107,7 +119,7 @@ public Optional<Tag> getOptionalTag(Object projectIdOrPath, String tagName) thro
107119
/**
108120
* Creates a tag on a particular ref of the given project. A message and release notes are optional.
109121
*
110-
* POST /projects/:id/repository/tags
122+
* <pre><code>GitLab Endpoint: POST /projects/:id/repository/tags</code></pre>
111123
*
112124
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
113125
* @param tagName The name of the tag Must be unique for the project
@@ -134,7 +146,7 @@ public Tag createTag(Object projectIdOrPath, String tagName, String ref, String
134146
* release notes are optional. This method is the same as {@link #createTag(Object, String, String, String, String)},
135147
* but instead allows the release notes to be supplied in a file.
136148
*
137-
* POST /projects/:id/repository/tags
149+
* <pre><code>GitLab Endpoint: POST /projects/:id/repository/tags</code></pre>
138150
*
139151
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
140152
* @param tagName the name of the tag, must be unique for the project
@@ -163,7 +175,7 @@ public Tag createTag(Object projectIdOrPath, String tagName, String ref, String
163175
/**
164176
* Deletes the tag from a project with the specified tag name.
165177
*
166-
* DELETE /projects/:id/repository/tags/:tag_name
178+
* <pre><code>GitLab Endpoint: DELETE /projects/:id/repository/tags/:tag_name</code></pre>
167179
*
168180
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
169181
* @param tagName The name of the tag to delete
@@ -177,7 +189,7 @@ public void deleteTag(Object projectIdOrPath, String tagName) throws GitLabApiEx
177189
/**
178190
* Add release notes to the existing git tag.
179191
*
180-
* POST /projects/:id/repository/tags/:tagName/release
192+
* <pre><code>GitLab Endpoint: POST /projects/:id/repository/tags/:tagName/release</code></pre>
181193
*
182194
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
183195
* @param tagName the name of a tag
@@ -195,7 +207,7 @@ public Release createRelease(Object projectIdOrPath, String tagName, String rele
195207
/**
196208
* Updates the release notes of a given release.
197209
*
198-
* PUT /projects/:id/repository/tags/:tagName/release
210+
* <pre><code>GitLab Endpoint: PUT /projects/:id/repository/tags/:tagName/release</code></pre>
199211
*
200212
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
201213
* @param tagName the name of a tag

0 commit comments

Comments
 (0)