Commit 3119c6fc authored by Greg Messner's avatar Greg Messner
Browse files

Now uses Constants enums instead of String literals.

parent c9964e64
package org.gitlab4j.api;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApiConstants.PipelineOrderBy;
import org.gitlab4j.api.GitLabApiConstants.PipelineScope;
import org.gitlab4j.api.GitLabApiConstants.SortOrder;
import org.gitlab4j.api.models.Pipeline;
import org.gitlab4j.api.models.PipelineStatus;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* This class provides an entry point to all the GitLab API pipeline calls.
*/
public class PipelineApi extends AbstractApi {
/** Enum to use for specifying the scope when calling getPipelines(). */
public enum Scope {
RUNNING, PENDING, FINISHED, BRANCHES, TAGS;
private static Map<String, Scope> valuesMap = new HashMap<>(5);
static {
for (Scope scope : Scope.values())
valuesMap.put(scope.toValue(), scope);
}
@JsonCreator
public static Scope forValue(String value) {
return valuesMap.get(value);
}
@JsonValue
public String toValue() {
return (name().toLowerCase());
}
@Override
public String toString() {
return (name().toLowerCase());
}
}
/** Enum to use for ordering the results of getPipelines(). */
public enum OrderBy {
ID, STATUS, REF, USER_ID;
private static Map<String, OrderBy> valuesMap = new HashMap<>(4);
static {
for (OrderBy orderBy : OrderBy.values())
valuesMap.put(orderBy.toValue(), orderBy);
}
@JsonCreator
public static OrderBy forValue(String value) {
return valuesMap.get(value);
}
@JsonValue
public String toValue() {
return (name().toLowerCase());
}
@Override
public String toString() {
return (name().toLowerCase());
}
}
public class PipelineApi extends AbstractApi implements GitLabApiConstants {
public PipelineApi(GitLabApi gitLabApi) {
super(gitLabApi);
......@@ -104,12 +48,12 @@ public class PipelineApi extends AbstractApi {
* @param name the name of the user who triggered pipelines
* @param username the username of the user who triggered pipelines
* @param orderBy order pipelines by ID, STATUS, REF, USER_ID (default: ID)
* @param sort sort pipelines in "ASC" or "DESC" order (default: "DESC")
* @param sort sort pipelines in ASC or DESC order (default: DESC)
* @return a list containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public List<Pipeline> getPipelines(int projectId, Scope scope, PipelineStatus status, String ref, boolean yamlErrors,
String name, String username, OrderBy orderBy, String sort) throws GitLabApiException {
public List<Pipeline> getPipelines(int projectId, PipelineScope scope, PipelineStatus status, String ref, boolean yamlErrors,
String name, String username, PipelineOrderBy orderBy, SortOrder sort) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope)
.withParam("status", status)
......@@ -118,7 +62,7 @@ public class PipelineApi extends AbstractApi {
.withParam("name", name)
.withParam("username", username)
.withParam("order_by", orderBy)
.withParam("sort", (sort != null ? sort.toLowerCase() : null));
.withParam("sort", sort);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "pipelines");
return (response.readEntity(new GenericType<List<Pipeline>>() {
......
......@@ -8,6 +8,8 @@ import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApiConstants.ProjectOrderBy;
import org.gitlab4j.api.GitLabApiConstants.SortOrder;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Event;
import org.gitlab4j.api.models.Issue;
......@@ -58,6 +60,8 @@ public class ProjectApi extends AbstractApi {
* @param statistics include project statistics
* @return a list of projects accessible by the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
* @deprecated Will be removed in version 5.0, replaced by {@link #getProjects(Boolean, Visibility,
* ProjectOrderBy, SortOrder, String, Boolean, Boolean, Boolean, Boolean, Boolean)}
*/
public List<Project> getProjects(Boolean archived, Visibility visibility, String orderBy,
String sort, String search, Boolean simple, Boolean owned, Boolean membership,
......@@ -81,6 +85,48 @@ public class ProjectApi extends AbstractApi {
}));
}
/**
* Get a list of projects accessible by the authenticated user and matching the supplied filter parameters.
* All filter parameters are optional.
*
* GET /projects
*
* @param archived limit by archived status
* @param visibility limit by visibility public, internal, or private
* @param orderBy return projects ordered by ID, NAME, PATH, CREATED_AT, UPDATED_AT, or
* LAST_ACTIVITY_AT fields, default is CREATED_AT
* @param sort return projects sorted in asc or desc order. Default is desc
* @param search return list of projects matching the search criteria
* @param simple return only the ID, URL, name, and path of each project
* @param owned limit by projects owned by the current user
* @param membership limit by projects that the current user is a member of
* @param starred limit by projects starred by the current user
* @param statistics include project statistics
* @return a list of projects accessible by the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public List<Project> getProjects(Boolean archived, Visibility visibility, ProjectOrderBy orderBy,
SortOrder sort, String search, Boolean simple, Boolean owned, Boolean membership,
Boolean starred, Boolean statistics) throws GitLabApiException {
GitLabApiForm formData = 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("per_page", getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects");
return (response.readEntity(new GenericType<List<Project>>() {
}));
}
/**
* Get a list of projects accessible by the authenticated user that match the provided search string.
*
......@@ -160,7 +206,9 @@ public class ProjectApi extends AbstractApi {
*/
public List<Project> getStarredProjects() throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("starred", true).withParam("per_page", getDefaultPerPage());
Form formData = new GitLabApiForm()
.withParam("starred", true)
.withParam("per_page", getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects");
return (response.readEntity(new GenericType<List<Project>>() {
}));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment