Commit 106003bf authored by Khosrow Moossavi's avatar Khosrow Moossavi Committed by Greg Messner
Browse files

Add Pipeline API

parent 73420ee4
...@@ -27,6 +27,7 @@ public class GitLabApi { ...@@ -27,6 +27,7 @@ public class GitLabApi {
private GroupApi groupApi; private GroupApi groupApi;
private MergeRequestApi mergeRequestApi; private MergeRequestApi mergeRequestApi;
private NamespaceApi namespaceApi; private NamespaceApi namespaceApi;
private PipelineApi pipelineApi;
private ProjectApi projectApi; private ProjectApi projectApi;
private RepositoryApi repositoryApi; private RepositoryApi repositoryApi;
private RepositoryFileApi repositoryFileApi; private RepositoryFileApi repositoryFileApi;
...@@ -175,6 +176,7 @@ public class GitLabApi { ...@@ -175,6 +176,7 @@ public class GitLabApi {
groupApi = new GroupApi(this); groupApi = new GroupApi(this);
mergeRequestApi = new MergeRequestApi(this); mergeRequestApi = new MergeRequestApi(this);
setNamespaceApi(new NamespaceApi(this)); setNamespaceApi(new NamespaceApi(this));
pipelineApi = new PipelineApi(this);
projectApi = new ProjectApi(this); projectApi = new ProjectApi(this);
repositoryApi = new RepositoryApi(this); repositoryApi = new RepositoryApi(this);
servicesApi = new ServicesApi(this); servicesApi = new ServicesApi(this);
...@@ -276,6 +278,16 @@ public class GitLabApi { ...@@ -276,6 +278,16 @@ public class GitLabApi {
return (groupApi); return (groupApi);
} }
/**
* Gets the PipelineApi instance owned by this GitLabApi instance. The PipelineApi is used
* to perform all pipeline related API calls.
*
* @return the PipelineApi instance owned by this GitLabApi instance
*/
public PipelineApi getPipelineApi() {
return (pipelineApi);
}
/** /**
* Gets the ProjectApi instance owned by this GitLabApi instance. The ProjectApi is used * Gets the ProjectApi instance owned by this GitLabApi instance. The ProjectApi is used
* to perform all project related API calls. * to perform all project related API calls.
...@@ -283,7 +295,7 @@ public class GitLabApi { ...@@ -283,7 +295,7 @@ public class GitLabApi {
* @return the ProjectApi instance owned by this GitLabApi instance * @return the ProjectApi instance owned by this GitLabApi instance
*/ */
public ProjectApi getProjectApi() { public ProjectApi getProjectApi() {
return (projectApi); return (projectApi);
} }
/** /**
......
package org.gitlab4j.api;
import java.util.List;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.models.Pipeline;
/**
* This class provides an entry point to all the GitLab API pipeline calls.
*/
public class PipelineApi extends AbstractApi {
public PipelineApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Get a list of pipelines in a project.
*
* GET /projects/:id/pipelines
*
* @param projectId the project ID to get the list of pipelines for
* @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) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "pipelines");
return (response.readEntity(new GenericType<List<Pipeline>>() {
}));
}
/**
* Get a list of pipelines in a project.
*
* GET /projects/:id/pipelines
*
* @param projectId the project ID to get the list of pipelines for
* @param scope
* @param status
* @param ref
* @param yamlErrors
* @param name
* @param username
* @param orderBy
* @param sort
* @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 {
GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope)
.withParam("status", status)
.withParam("ref", ref)
.withParam("yaml_errors", yamlErrors)
.withParam("name", name)
.withParam("username", username)
.withParam("order_by", orderBy)
.withParam("sort", sort);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "pipelines");
return (response.readEntity(new GenericType<List<Pipeline>>() {
}));
}
/**
* Get single pipelines in a project.
*
* GET /projects/:id/pipelines/:pipeline_id
*
* @param projectId the project ID to get the specified pipeline for
* @param pipelineId the pipeline ID to get
* @return a single pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Pipeline getPipeline(int projectId, int pipelineId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "pipelines", pipelineId);
return (response.readEntity(Pipeline.class));
}
/**
* Create a pipelines in a project.
*
* POST /projects/:id/pipelines
*
* @param projectId the project ID to create a pipeline in
* @param ref
* @return a Pipeline instance with the newly created pipeline info
* @throws GitLabApiException if any exception occurs during execution
*/
public Pipeline createPipeline(int projectId, String ref) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("ref", ref);
Response response = post(Response.Status.OK, formData.asMap(), "projects", projectId, "pipelines");
return (response.readEntity(Pipeline.class));
}
/**
* Retry a job in specified pipelines in a project.
*
* POST /projects/:id/pipelines/:pipeline_id/retry
*
* @param projectId the project ID to retry a job for speficied pipeline
* @param pipelineId the pipeline ID to retry a job from
* @return pipeline instance which just retried
* @throws GitLabApiException if any exception occurs during execution
*/
public Pipeline retryPipelineJob(int projectId, int pipelineId) throws GitLabApiException {
GitLabApiForm formData = null;
Response response = post(Response.Status.OK, formData, "projects", projectId, "pipelines", pipelineId, "retry");
return (response.readEntity(Pipeline.class));
}
/**
* Cancel jobs of specified pipelines in a project.
*
* POST /projects/:id/pipelines/:pipeline_id/cancel
*
* @param projectId the project ID to cancel jobs for speficied pipeline
* @param pipelineId the pipeline ID to cancel jobs
* @return pipeline instance which just canceled
* @throws GitLabApiException if any exception occurs during execution
*/
public Pipeline cancelPipelineJobs(int projectId, int pipelineId) throws GitLabApiException {
GitLabApiForm formData = null;
Response response = post(Response.Status.OK, formData, "projects", projectId, "pipelines", pipelineId, "cancel");
return (response.readEntity(Pipeline.class));
}
}
package org.gitlab4j.api.models;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Pipeline {
private Integer id;
private String status;
private String ref;
private String sha;
private String beforeSha;
private String yamlErrors;
private User user;
private Date createdAt;
private Date updated_at;
private Date started_at;
private Date finished_at;
private Date committed_at;
private String coverage;
private Integer duration;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getRef() {
return ref;
}
public void setRef(String ref) {
this.ref = ref;
}
public String getSha() {
return sha;
}
public void setSha(String sha) {
this.sha = sha;
}
public String getBeforeSha() {
return beforeSha;
}
public void setBeforeSha(String beforeSha) {
this.beforeSha = beforeSha;
}
public String getYamlErrors() {
return yamlErrors;
}
public void setYamlErrors(String yamlErrors) {
this.yamlErrors = yamlErrors;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdated_at() {
return updated_at;
}
public void setUpdated_at(Date updated_at) {
this.updated_at = updated_at;
}
public Date getStarted_at() {
return started_at;
}
public void setStarted_at(Date started_at) {
this.started_at = started_at;
}
public Date getFinished_at() {
return finished_at;
}
public void setFinished_at(Date finished_at) {
this.finished_at = finished_at;
}
public Date getCommitted_at() {
return committed_at;
}
public void setCommitted_at(Date committed_at) {
this.committed_at = committed_at;
}
public String getCoverage() {
return coverage;
}
public void setCoverage(String coverage) {
this.coverage = coverage;
}
public Integer getDuration() {
return duration;
}
public void setDuration(Integer duration) {
this.duration = duration;
}
}
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