Skip to content
Merged
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To utilize the GitLab API for Java in your project, simply add the following dep
```java
dependencies {
...
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.8.54'
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.8.56'
}
```

Expand All @@ -22,7 +22,7 @@ dependencies {
<dependency>
<groupId>org.gitlab4j</groupId>
<artifactId>gitlab4j-api</artifactId>
<version>4.8.54</version>
<version>4.8.56</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.gitlab4j</groupId>
<artifactId>gitlab4j-api</artifactId>
<packaging>jar</packaging>
<version>4.8.55-SNAPSHOT</version>
<version>4.8.57-SNAPSHOT</version>
<name>GitLab API Java Client</name>
<description>GitLab API for Java (gitlab4j-api) provides a full featured Java API for working with GitLab repositories via the GitLab REST API.</description>
<url>https://github.com/gmessner/gitlab4j-api</url>
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/gitlab4j/api/GroupApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.gitlab4j.api.models.Group;
import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.GroupProjectsFilter;
import org.gitlab4j.api.models.Visibility;

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

/**
* Get a list of projects belonging to the specified group ID and filter.
*
* GET /groups/:id/projects
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param filter the GroupProjectsFilter instance holding the filter values for the query
* @return a List containing Project instances that belong to the group and match the provided filter
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(Object groupIdOrPath, GroupProjectsFilter filter) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
Response response = get(Response.Status.OK, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}

/**
* Get a Pager of projects belonging to the specified group ID and filter.
*
* GET /groups/:id/projects
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param filter the GroupProjectsFilter instance holding the filter values for the query
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager containing Project instances that belong to the group and match the provided filter
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getProjects(Object groupIdOrPath, GroupProjectsFilter filter, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "projects"));
}

/**
* Get a list of projects belonging to the specified group ID.
*
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/gitlab4j/api/JobApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ public InputStream downloadArtifactsFile(Object projectIdOrPath, Integer jobId,
*/
public File downloadSingleArtifactsFile(Object projectIdOrPath, Integer jobId, Path artifactPath, File directory) throws GitLabApiException {

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

if (directory == null)
Expand Down Expand Up @@ -364,7 +366,9 @@ public File downloadSingleArtifactsFile(Object projectIdOrPath, Integer jobId, P
* @throws GitLabApiException if any exception occurs
*/
public InputStream downloadSingleArtifactsFile(Object projectIdOrPath, Integer jobId, Path artifactPath) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts", artifactPath);
String path = artifactPath.toString().replace("\\", "/");
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts", path);
return (response.readEntity(InputStream.class));
}

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

Expand Down
166 changes: 166 additions & 0 deletions src/main/java/org/gitlab4j/api/models/GroupProjectsFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package org.gitlab4j.api.models;

import org.gitlab4j.api.Constants.ProjectOrderBy;
import org.gitlab4j.api.Constants.SortOrder;
import org.gitlab4j.api.GitLabApiForm;

/**
* This class is used to filter Projects when getting lists of projects for a specified group.
*/
public class GroupProjectsFilter {

private Boolean archived;
private Visibility visibility;
private ProjectOrderBy orderBy;
private SortOrder sort;
private String search;
private Boolean simple;
private Boolean owned;
private Boolean starred;
private Boolean withCustomAttributes;
private Boolean withIssuesEnabled;
private Boolean withMergeRequestsEnabled;

/**
* Limit by archived status.
*
* @param archived if true will only return archived projects
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withArchived(Boolean archived) {
this.archived = archived;
return (this);
}

/**
* Limit by visibility public, internal, or private.
*
* @param visibility the visibility to match
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withVisibility(Visibility visibility) {
this.visibility = visibility;
return (this);
}

/**
* Return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields. Default is created_at.
*
* @param orderBy specifies what field to order by
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withOrderBy(ProjectOrderBy orderBy) {
this.orderBy = orderBy;
return (this);
}

/**
* Return projects sorted in asc or desc order. Default is desc.
*
* @param sort sort direction, ASC or DESC
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withSortOder(SortOrder sort) {
this.sort = sort;
return (this);
}

/**
* Return list of projects matching the search criteria.
*
* @param search the search criteria
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withSearch(String search) {
this.search = search;
return (this);
}

/**
* Return only limited fields for each project. This is a no-op without
* authentication as then only simple fields are returned.
*
* @param simple if true, return only limited fields for each project
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withSimple(Boolean simple) {
this.simple = simple;
return (this);
}

/**
* Limit by projects explicitly owned by the current user
*
* @param owned if true, limit to projects explicitly owned by the current user
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withOwned(Boolean owned) {
this.owned = owned;
return (this);
}

/**
* Limit by projects starred by the current user.
*
* @param starred if true, limit by projects starred by the current user
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withStarred(Boolean starred) {
this.starred = starred;
return (this);
}

/**
* Include custom attributes in response (admins only).
*
* @param withCustomAttributes if true, include custom attributes in the repsonse
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withCustomAttributes(Boolean withCustomAttributes) {
this.withCustomAttributes = withCustomAttributes;
return (this);
}

/**
* Limit by enabled issues feature
*
* @param withIssuesEnabled if true, limit by enabled issues feature
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withIssuesEnabled(Boolean withIssuesEnabled) {
this.withIssuesEnabled = withIssuesEnabled;
return (this);
}

/**
* Limit by enabled merge requests feature
*
* @param withMergeRequestsEnabled if true, imit by enabled merge requests feature
* @return the reference to this ProjectFilter instance
*/
public GroupProjectsFilter withMergeRequestsEnabled(Boolean withMergeRequestsEnabled) {
this.withMergeRequestsEnabled = withMergeRequestsEnabled;
return (this);
}

/**
* Get the query params specified by this filter.
*
* @return a GitLabApiForm instance holding the query parameters for this ProjectFilter instance
*/
public GitLabApiForm getQueryParams() {
return (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("starred", starred)
.withParam("with_custom_attributes", withCustomAttributes)
.withParam("with_issues_enabled", withIssuesEnabled)
.withParam("with_merge_requests_enabled ", withMergeRequestsEnabled)
);
}
}