Skip to content

Add all parameters to get project of group api #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 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.ProjectOfGroupFilter;
import org.gitlab4j.api.models.Visibility;

/**
Expand Down Expand Up @@ -224,6 +225,21 @@ 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.
*
* 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 ProjectOfGroupFilter instance holding the filter values for the query
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(Object groupIdOrPath, ProjectOfGroupFilter 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 list of projects belonging to the specified group ID.
*
Expand Down
167 changes: 167 additions & 0 deletions src/main/java/org/gitlab4j/api/models/ProjectOfGroupFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package org.gitlab4j.api.models;

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

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

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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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 ProjectOfGroupFilter 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)
);
}
}