Commit 0038a559 authored by Greg Messner's avatar Greg Messner
Browse files

Modified to use enums instead of String literals.

parent 73d38d00
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.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 PipelineApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
......@@ -37,19 +97,19 @@ public class PipelineApi extends AbstractApi {
* GET /projects/:id/pipelines
*
* @param projectId the project ID to get the list of pipelines for
* @param scope the scope of pipelines, one of: running, pending, finished, branches, tags
* @param status the status of pipelines, one of: running, pending, success, failed, canceled, skipped
* @param scope the scope of pipelines, one of: RUNNING, PENDING, FINISHED, BRANCHES, TAGS
* @param status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
* @param ref the ref of pipelines
* @param yamlErrors returns pipelines with invalid configurations
* @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, or user_id (default: id)
* @param sort sort pipelines in asc or desc order (default: desc)
* @param orderBy order pipelines by ID, STATUS, REF, USER_ID (default: ID)
* @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, String scope, String status, String ref, boolean yamlErrors,
String name, String username, String orderBy, String sort) throws GitLabApiException {
public List<Pipeline> getPipelines(int projectId, Scope scope, PipelineStatus status, String ref, boolean yamlErrors,
String name, String username, OrderBy orderBy, String sort) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope)
.withParam("status", status)
......@@ -58,7 +118,7 @@ public class PipelineApi extends AbstractApi {
.withParam("name", name)
.withParam("username", username)
.withParam("order_by", orderBy)
.withParam("sort", sort);
.withParam("sort", (sort != null ? sort.toLowerCase() : null));
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "pipelines");
return (response.readEntity(new GenericType<List<Pipeline>>() {
......
......@@ -11,7 +11,7 @@ import javax.xml.bind.annotation.XmlRootElement;
public class Pipeline {
private Integer id;
private String status;
private PipelineStatus status;
private String ref;
private String sha;
private String beforeSha;
......@@ -34,11 +34,11 @@ public class Pipeline {
this.id = id;
}
public String getStatus() {
public PipelineStatus getStatus() {
return status;
}
public void setStatus(String status) {
public void setStatus(PipelineStatus status) {
this.status = status;
}
......
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