Skip to content

Commit 54ca8b1

Browse files
authored
Merge pull request #3 from gmessner/master
Update to commit b78db14
2 parents 495358c + 2800069 commit 54ca8b1

File tree

5 files changed

+210
-6
lines changed

5 files changed

+210
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To utilize the GitLab API for Java in your project, simply add the following dep
1111
```java
1212
dependencies {
1313
...
14-
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.8.54'
14+
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.8.56'
1515
}
1616
```
1717

@@ -22,7 +22,7 @@ dependencies {
2222
<dependency>
2323
<groupId>org.gitlab4j</groupId>
2424
<artifactId>gitlab4j-api</artifactId>
25-
<version>4.8.54</version>
25+
<version>4.8.56</version>
2626
</dependency>
2727
```
2828

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>org.gitlab4j</groupId>
66
<artifactId>gitlab4j-api</artifactId>
77
<packaging>jar</packaging>
8-
<version>4.8.55-SNAPSHOT</version>
8+
<version>4.8.57-SNAPSHOT</version>
99
<name>GitLab API Java Client</name>
1010
<description>GitLab API for Java (gitlab4j-api) provides a full featured Java API for working with GitLab repositories via the GitLab REST API.</description>
1111
<url>https://github.com/gmessner/gitlab4j-api</url>

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.gitlab4j.api.models.Group;
1414
import org.gitlab4j.api.models.Member;
1515
import org.gitlab4j.api.models.Project;
16+
import org.gitlab4j.api.models.GroupProjectsFilter;
1617
import org.gitlab4j.api.models.Visibility;
1718

1819
/**
@@ -224,6 +225,38 @@ public Pager<Group> getSubGroups(Integer groupId, List<Integer> skipGroups, Bool
224225
return (new Pager<Group>(this, Group.class, itemsPerPage, formData.asMap(), "groups", groupId, "subgroups"));
225226
}
226227

228+
/**
229+
* Get a list of projects belonging to the specified group ID and filter.
230+
*
231+
* GET /groups/:id/projects
232+
*
233+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
234+
* @param filter the GroupProjectsFilter instance holding the filter values for the query
235+
* @return a List containing Project instances that belong to the group and match the provided filter
236+
* @throws GitLabApiException if any exception occurs
237+
*/
238+
public List<Project> getProjects(Object groupIdOrPath, GroupProjectsFilter filter) throws GitLabApiException {
239+
GitLabApiForm formData = filter.getQueryParams();
240+
Response response = get(Response.Status.OK, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "projects");
241+
return (response.readEntity(new GenericType<List<Project>>() {}));
242+
}
243+
244+
/**
245+
* Get a Pager of projects belonging to the specified group ID and filter.
246+
*
247+
* GET /groups/:id/projects
248+
*
249+
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
250+
* @param filter the GroupProjectsFilter instance holding the filter values for the query
251+
* @param itemsPerPage the number of Project instances that will be fetched per page
252+
* @return a Pager containing Project instances that belong to the group and match the provided filter
253+
* @throws GitLabApiException if any exception occurs
254+
*/
255+
public Pager<Project> getProjects(Object groupIdOrPath, GroupProjectsFilter filter, int itemsPerPage) throws GitLabApiException {
256+
GitLabApiForm formData = filter.getQueryParams();
257+
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "projects"));
258+
}
259+
227260
/**
228261
* Get a list of projects belonging to the specified group ID.
229262
*

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ public InputStream downloadArtifactsFile(Object projectIdOrPath, Integer jobId,
332332
*/
333333
public File downloadSingleArtifactsFile(Object projectIdOrPath, Integer jobId, Path artifactPath, File directory) throws GitLabApiException {
334334

335-
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts", artifactPath);
335+
String path = artifactPath.toString().replace("\\", "/");
336+
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
337+
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts", path);
336338
try {
337339

338340
if (directory == null)
@@ -364,7 +366,9 @@ public File downloadSingleArtifactsFile(Object projectIdOrPath, Integer jobId, P
364366
* @throws GitLabApiException if any exception occurs
365367
*/
366368
public InputStream downloadSingleArtifactsFile(Object projectIdOrPath, Integer jobId, Path artifactPath) throws GitLabApiException {
367-
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts", artifactPath);
369+
String path = artifactPath.toString().replace("\\", "/");
370+
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
371+
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts", path);
368372
return (response.readEntity(InputStream.class));
369373
}
370374

@@ -380,7 +384,8 @@ public InputStream downloadSingleArtifactsFile(Object projectIdOrPath, Integer j
380384
* @throws GitLabApiException if any exception occurs during execution
381385
*/
382386
public String getTrace(Object projectIdOrPath, int jobId) throws GitLabApiException {
383-
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "trace");
387+
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
388+
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "trace");
384389
return (response.readEntity(String.class));
385390
}
386391

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package org.gitlab4j.api.models;
2+
3+
import org.gitlab4j.api.Constants.ProjectOrderBy;
4+
import org.gitlab4j.api.Constants.SortOrder;
5+
import org.gitlab4j.api.GitLabApiForm;
6+
7+
/**
8+
* This class is used to filter Projects when getting lists of projects for a specified group.
9+
*/
10+
public class GroupProjectsFilter {
11+
12+
private Boolean archived;
13+
private Visibility visibility;
14+
private ProjectOrderBy orderBy;
15+
private SortOrder sort;
16+
private String search;
17+
private Boolean simple;
18+
private Boolean owned;
19+
private Boolean starred;
20+
private Boolean withCustomAttributes;
21+
private Boolean withIssuesEnabled;
22+
private Boolean withMergeRequestsEnabled;
23+
24+
/**
25+
* Limit by archived status.
26+
*
27+
* @param archived if true will only return archived projects
28+
* @return the reference to this ProjectFilter instance
29+
*/
30+
public GroupProjectsFilter withArchived(Boolean archived) {
31+
this.archived = archived;
32+
return (this);
33+
}
34+
35+
/**
36+
* Limit by visibility public, internal, or private.
37+
*
38+
* @param visibility the visibility to match
39+
* @return the reference to this ProjectFilter instance
40+
*/
41+
public GroupProjectsFilter withVisibility(Visibility visibility) {
42+
this.visibility = visibility;
43+
return (this);
44+
}
45+
46+
/**
47+
* Return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields. Default is created_at.
48+
*
49+
* @param orderBy specifies what field to order by
50+
* @return the reference to this ProjectFilter instance
51+
*/
52+
public GroupProjectsFilter withOrderBy(ProjectOrderBy orderBy) {
53+
this.orderBy = orderBy;
54+
return (this);
55+
}
56+
57+
/**
58+
* Return projects sorted in asc or desc order. Default is desc.
59+
*
60+
* @param sort sort direction, ASC or DESC
61+
* @return the reference to this ProjectFilter instance
62+
*/
63+
public GroupProjectsFilter withSortOder(SortOrder sort) {
64+
this.sort = sort;
65+
return (this);
66+
}
67+
68+
/**
69+
* Return list of projects matching the search criteria.
70+
*
71+
* @param search the search criteria
72+
* @return the reference to this ProjectFilter instance
73+
*/
74+
public GroupProjectsFilter withSearch(String search) {
75+
this.search = search;
76+
return (this);
77+
}
78+
79+
/**
80+
* Return only limited fields for each project. This is a no-op without
81+
* authentication as then only simple fields are returned.
82+
*
83+
* @param simple if true, return only limited fields for each project
84+
* @return the reference to this ProjectFilter instance
85+
*/
86+
public GroupProjectsFilter withSimple(Boolean simple) {
87+
this.simple = simple;
88+
return (this);
89+
}
90+
91+
/**
92+
* Limit by projects explicitly owned by the current user
93+
*
94+
* @param owned if true, limit to projects explicitly owned by the current user
95+
* @return the reference to this ProjectFilter instance
96+
*/
97+
public GroupProjectsFilter withOwned(Boolean owned) {
98+
this.owned = owned;
99+
return (this);
100+
}
101+
102+
/**
103+
* Limit by projects starred by the current user.
104+
*
105+
* @param starred if true, limit by projects starred by the current user
106+
* @return the reference to this ProjectFilter instance
107+
*/
108+
public GroupProjectsFilter withStarred(Boolean starred) {
109+
this.starred = starred;
110+
return (this);
111+
}
112+
113+
/**
114+
* Include custom attributes in response (admins only).
115+
*
116+
* @param withCustomAttributes if true, include custom attributes in the repsonse
117+
* @return the reference to this ProjectFilter instance
118+
*/
119+
public GroupProjectsFilter withCustomAttributes(Boolean withCustomAttributes) {
120+
this.withCustomAttributes = withCustomAttributes;
121+
return (this);
122+
}
123+
124+
/**
125+
* Limit by enabled issues feature
126+
*
127+
* @param withIssuesEnabled if true, limit by enabled issues feature
128+
* @return the reference to this ProjectFilter instance
129+
*/
130+
public GroupProjectsFilter withIssuesEnabled(Boolean withIssuesEnabled) {
131+
this.withIssuesEnabled = withIssuesEnabled;
132+
return (this);
133+
}
134+
135+
/**
136+
* Limit by enabled merge requests feature
137+
*
138+
* @param withMergeRequestsEnabled if true, imit by enabled merge requests feature
139+
* @return the reference to this ProjectFilter instance
140+
*/
141+
public GroupProjectsFilter withMergeRequestsEnabled(Boolean withMergeRequestsEnabled) {
142+
this.withMergeRequestsEnabled = withMergeRequestsEnabled;
143+
return (this);
144+
}
145+
146+
/**
147+
* Get the query params specified by this filter.
148+
*
149+
* @return a GitLabApiForm instance holding the query parameters for this ProjectFilter instance
150+
*/
151+
public GitLabApiForm getQueryParams() {
152+
return (new GitLabApiForm()
153+
.withParam("archived", archived)
154+
.withParam("visibility", visibility)
155+
.withParam("order_by", orderBy)
156+
.withParam("sort", sort)
157+
.withParam("search", search)
158+
.withParam("simple", simple)
159+
.withParam("owned", owned)
160+
.withParam("starred", starred)
161+
.withParam("with_custom_attributes", withCustomAttributes)
162+
.withParam("with_issues_enabled", withIssuesEnabled)
163+
.withParam("with_merge_requests_enabled ", withMergeRequestsEnabled)
164+
);
165+
}
166+
}

0 commit comments

Comments
 (0)