Commit df274ee4 authored by Greg Messner's avatar Greg Messner
Browse files

Added support for deleting and keeping job artifacts (#493).

parent a56573ee
...@@ -172,7 +172,7 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -172,7 +172,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return a single job for the specified project ID * @return a single job for the specified project ID
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Job getJob(Object projectIdOrPath, int jobId) throws GitLabApiException { public Job getJob(Object projectIdOrPath, Integer jobId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId); Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId);
return (response.readEntity(Job.class)); return (response.readEntity(Job.class));
} }
...@@ -186,7 +186,7 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -186,7 +186,7 @@ public class JobApi extends AbstractApi implements Constants {
* @param jobId the job ID to get * @param jobId the job ID to get
* @return a single job for the specified project ID as an Optional intance * @return a single job for the specified project ID as an Optional intance
*/ */
public Optional<Job> getOptionalJob(Object projectIdOrPath, int jobId) { public Optional<Job> getOptionalJob(Object projectIdOrPath, Integer jobId) {
try { try {
return (Optional.ofNullable(getJob(projectIdOrPath, jobId))); return (Optional.ofNullable(getJob(projectIdOrPath, jobId)));
} catch (GitLabApiException glae) { } catch (GitLabApiException glae) {
...@@ -422,7 +422,7 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -422,7 +422,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return a String containing the specified job's trace * @return a String containing the specified job's trace
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public String getTrace(Object projectIdOrPath, int jobId) throws GitLabApiException { public String getTrace(Object projectIdOrPath, Integer jobId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(), Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "trace"); "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "trace");
return (response.readEntity(String.class)); return (response.readEntity(String.class));
...@@ -438,7 +438,7 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -438,7 +438,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return job instance which just canceled * @return job instance which just canceled
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Job cancleJob(Object projectIdOrPath, int jobId) throws GitLabApiException { public Job cancleJob(Object projectIdOrPath, Integer jobId) throws GitLabApiException {
GitLabApiForm formData = null; GitLabApiForm formData = null;
Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "cancel"); Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "cancel");
return (response.readEntity(Job.class)); return (response.readEntity(Job.class));
...@@ -454,7 +454,7 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -454,7 +454,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return job instance which just retried * @return job instance which just retried
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Job retryJob(Object projectIdOrPath, int jobId) throws GitLabApiException { public Job retryJob(Object projectIdOrPath, Integer jobId) throws GitLabApiException {
GitLabApiForm formData = null; GitLabApiForm formData = null;
Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "retry"); Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "retry");
return (response.readEntity(Job.class)); return (response.readEntity(Job.class));
...@@ -470,7 +470,7 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -470,7 +470,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return job instance which just erased * @return job instance which just erased
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Job eraseJob(Object projectIdOrPath, int jobId) throws GitLabApiException { public Job eraseJob(Object projectIdOrPath, Integer jobId) throws GitLabApiException {
GitLabApiForm formData = null; GitLabApiForm formData = null;
Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "erase"); Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "erase");
return (response.readEntity(Job.class)); return (response.readEntity(Job.class));
...@@ -486,9 +486,38 @@ public class JobApi extends AbstractApi implements Constants { ...@@ -486,9 +486,38 @@ public class JobApi extends AbstractApi implements Constants {
* @return job instance which just played * @return job instance which just played
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Job playJob(Object projectIdOrPath, int jobId) throws GitLabApiException { public Job playJob(Object projectIdOrPath, Integer jobId) throws GitLabApiException {
GitLabApiForm formData = null; GitLabApiForm formData = null;
Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play"); Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
return (response.readEntity(Job.class)); return (response.readEntity(Job.class));
} }
/**
* Prevents artifacts from being deleted when expiration is set.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/jobs/:job_id/artifacts</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the ID to keep artifacts for
* @return the Job instance that was just modified
* @throws GitLabApiException if any exception occurs during execution
*/
public Job keepArtifacts(Object projectIdOrPath, Integer jobId) throws GitLabApiException {
GitLabApiForm formData = null;
Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "keep");
return (response.readEntity(Job.class));
}
/**
* Delete artifacts of a job.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/jobs/:job_id/artifacts</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the ID to delete artifacts for
* @throws GitLabApiException if any exception occurs during execution
*/
public void deleteArtifacts(Object projectIdOrPath, Integer jobId) throws GitLabApiException {
delete(Status.NO_CONTENT, null, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "artifacts");
}
} }
...@@ -27,6 +27,8 @@ public class Job { ...@@ -27,6 +27,8 @@ public class Job {
private JobStatus status; private JobStatus status;
private String when; private String when;
private Boolean manual; private Boolean manual;
private Boolean allowFailure;
private Float duration;
public Integer getId() { public Integer getId() {
return id; return id;
...@@ -188,6 +190,22 @@ public class Job { ...@@ -188,6 +190,22 @@ public class Job {
this.manual = manual; this.manual = manual;
} }
public Boolean getAllowFailure() {
return allowFailure;
}
public void setAllowFailure(Boolean allowFailure) {
this.allowFailure = allowFailure;
}
public Float getDuration() {
return duration;
}
public void setDuration(Float duration) {
this.duration = duration;
}
public Job withId(Integer id) { public Job withId(Integer id) {
this.id = id; this.id = id;
return this; return this;
...@@ -273,6 +291,11 @@ public class Job { ...@@ -273,6 +291,11 @@ public class Job {
return this; return this;
} }
public Job allowFailureManual(Boolean allowFailure) {
this.allowFailure = allowFailure;
return this;
}
@Override @Override
public String toString() { public String toString() {
return (JacksonJson.toJsonString(this)); return (JacksonJson.toJsonString(this));
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
"status": "failed", "status": "failed",
"tag": false, "tag": false,
"web_url": "https://example.com/foo/bar/-/jobs/7", "web_url": "https://example.com/foo/bar/-/jobs/7",
"allow_failure": false,
"duration": 0.465,
"user": { "user": {
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"created_at": "2015-12-21T13:14:24.077Z", "created_at": "2015-12-21T13:14:24.077Z",
......
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