diff --git a/README.md b/README.md index 698f17d39..fe6a12a0f 100644 --- a/README.md +++ b/README.md @@ -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' } ``` @@ -22,7 +22,7 @@ dependencies { org.gitlab4j gitlab4j-api - 4.8.54 + 4.8.56 ``` diff --git a/pom.xml b/pom.xml index 2bb81a20f..a179cbf5e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.gitlab4j gitlab4j-api jar - 4.8.55-SNAPSHOT + 4.8.57-SNAPSHOT GitLab API Java Client GitLab API for Java (gitlab4j-api) provides a full featured Java API for working with GitLab repositories via the GitLab REST API. https://github.com/gmessner/gitlab4j-api diff --git a/src/main/java/org/gitlab4j/api/GroupApi.java b/src/main/java/org/gitlab4j/api/GroupApi.java index 1e1283f93..507949ff7 100644 --- a/src/main/java/org/gitlab4j/api/GroupApi.java +++ b/src/main/java/org/gitlab4j/api/GroupApi.java @@ -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; /** @@ -224,6 +225,38 @@ public Pager getSubGroups(Integer groupId, List skipGroups, Bool return (new Pager(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 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>() {})); + } + + /** + * 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 getProjects(Object groupIdOrPath, GroupProjectsFilter filter, int itemsPerPage) throws GitLabApiException { + GitLabApiForm formData = filter.getQueryParams(); + return (new Pager(this, Project.class, itemsPerPage, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "projects")); + } + /** * Get a list of projects belonging to the specified group ID. * diff --git a/src/main/java/org/gitlab4j/api/JobApi.java b/src/main/java/org/gitlab4j/api/JobApi.java index 6e7737ba7..5739a0e23 100644 --- a/src/main/java/org/gitlab4j/api/JobApi.java +++ b/src/main/java/org/gitlab4j/api/JobApi.java @@ -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) @@ -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)); } @@ -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)); } diff --git a/src/main/java/org/gitlab4j/api/models/GroupProjectsFilter.java b/src/main/java/org/gitlab4j/api/models/GroupProjectsFilter.java new file mode 100644 index 000000000..be359d9ab --- /dev/null +++ b/src/main/java/org/gitlab4j/api/models/GroupProjectsFilter.java @@ -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) + ); + } +}