Skip to content

Update to commit b7b2e3af0849e2810c800350d99d825b0c0ca9f2 #2

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
merged 5 commits into from
Nov 6, 2018
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
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.53'
compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.8.54'
}
```

Expand All @@ -22,7 +22,7 @@ dependencies {
<dependency>
<groupId>org.gitlab4j</groupId>
<artifactId>gitlab4j-api</artifactId>
<version>4.8.53</version>
<version>4.8.54</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.54-SNAPSHOT</version>
<version>4.8.55-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
37 changes: 37 additions & 0 deletions src/main/java/org/gitlab4j/api/AbstractApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Group;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.User;

/**
* This class is the base class for all the sub API classes. It provides implementations of
Expand Down Expand Up @@ -98,6 +99,42 @@ public Object getGroupIdOrPath(Object obj) throws GitLabApiException {
}
}

/**
* Returns the user ID or path from the provided Integer, String, or User instance.
*
* @param obj the object to determine the ID or username from
* @return the user ID or username from the provided Integer, String, or User instance
* @throws GitLabApiException if any exception occurs during execution
*/
public Object getUserIdOrUsername(Object obj) throws GitLabApiException {

if (obj == null) {
throw (new RuntimeException("Cannot determine ID or username from null object"));
} else if (obj instanceof Integer) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
} else if (obj instanceof User) {

Integer id = ((User) obj).getId();
if (id != null && id.intValue() > 0) {
return (id);
}

String username = ((User) obj).getUsername();
if (username != null && username.trim().length() > 0) {
return (urlEncode(username.trim()));
}

throw (new RuntimeException("Cannot determine ID or username from provided User instance"));

} else {

throw (new RuntimeException("Cannot determine ID or username from provided " + obj.getClass().getSimpleName() +
" instance, must be Integer, String, or a User instance"));
}
}

protected ApiVersion getApiVersion() {
return (gitLabApi.getApiVersion());
}
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/org/gitlab4j/api/ProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProjectFilter;
import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProjectUser;
import org.gitlab4j.api.models.PushRules;
Expand Down Expand Up @@ -464,6 +465,56 @@ public Pager<Project> getStarredProjects(int itemsPerPage) throws GitLabApiExcep
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(), "projects"));
}

/**
* Get a list of visible projects owned by the given user.
*
* <pre><code>GET /users/:user_id/projects</code></pre>
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @return a list of visible projects owned by the given use
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getUserProjects(Object userIdOrUsername, ProjectFilter filter) throws GitLabApiException {
return (getUserProjects(userIdOrUsername, filter, 1, getDefaultPerPage()));
}

/**
* Get a list of visible projects owned by the given user in the specified page range.
*
* <pre><code>GET /users/:user_id/projects</code></pre>
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of visible projects owned by the given use
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getUserProjects(Object userIdOrUsername, ProjectFilter filter, int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams(page, perPage);
Response response = get(Response.Status.OK, formData.asMap(),
"users", getUserIdOrUsername(userIdOrUsername), "projects");
return (response.readEntity(new GenericType<List<Project>>() {}));
}

/**
* Get a Pager of visible projects owned by the given user.
*
* <pre><code>GET /users/:user_id/projects</code></pre>
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of visible projects owned by the given use
* @throws GitLabApiException if any exception occurs
*/
public Pager<Project> getUserProjects(Object userIdOrUsername, ProjectFilter filter, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = filter.getQueryParams();
return (new Pager<Project>(this, Project.class, itemsPerPage, formData.asMap(),
"users", getUserIdOrUsername(userIdOrUsername), "projects"));
}

/**
* Get a specific project, which is owned by the authentication user.
*
Expand Down
219 changes: 219 additions & 0 deletions src/main/java/org/gitlab4j/api/models/ProjectFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
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 user.
*/
public class ProjectFilter {

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

/**
* Limit by archived status.
*
* @param archived if true will only return archived projects
* @return the reference to this ProjectFilter instance
*/
public ProjectFilter 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 ProjectFilter 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 ProjectFilter 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 ProjectFilter 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 ProjectFilter 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 ProjectFilter 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 ProjectFilter withOwned(Boolean owned) {
this.owned = owned;
return (this);
}

/**
* Limit by projects that the current user is a member of
*
* @param membership if true, limit by projects that the current user is a member of
* @return the reference to this ProjectFilter instance
*/
public ProjectFilter withMembership(Boolean membership) {
this.membership = membership;
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 ProjectFilter withStarred(Boolean starred) {
this.starred = starred;
return (this);
}

/**
* Include project statistics.
*
* @param statistics if true, include project statistics
* @return the reference to this ProjectFilter instance
*/
public ProjectFilter withStatistics(Boolean statistics) {
this.statistics = statistics;
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 ProjectFilter 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 ProjectFilter 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 ProjectFilter withMergeRequestsEnabled(Boolean withMergeRequestsEnabled) {
this.withMergeRequestsEnabled = withMergeRequestsEnabled;
return (this);
}

/**
* Limit by current user minimal access level
*
* @param minAccessLevel limit by current user minimal access level
* @return the reference to this ProjectFilter instance
*/
public ProjectFilter minAccessLevel(AccessLevel minAccessLevel) {
this.minAccessLevel = minAccessLevel;
return (this);
}

/**
* Get the query params specified by this filter.
*
* @param page specifies the page number
* @param perPage specifies the number of items per page
* @return a GitLabApiForm instance holding the query parameters for this ProjectFilter instance
*/
public GitLabApiForm getQueryParams(int page, int perPage) {
return (getQueryParams()
.withParam(Constants.PAGE_PARAM, page)
.withParam(Constants.PER_PAGE_PARAM, perPage));
}

/**
* 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("membership", membership)
.withParam("starred", starred)
.withParam("statistics", statistics)
.withParam("with_custom_attributes", withCustomAttributes)
.withParam("with_issues_enabled", withIssuesEnabled)
.withParam("with_merge_requests_enabled ", withMergeRequestsEnabled))
.withParam("min_access_level ", (minAccessLevel != null ? minAccessLevel.toValue() : null)
);
}
}