Skip to content

Extend "playJob" to support "job_variables_attributes" #836

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 1 commit into from
Feb 5, 2023
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
33 changes: 29 additions & 4 deletions src/main/java/org/gitlab4j/api/JobApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.gitlab4j.api.models.ArtifactsFile;
import org.gitlab4j.api.models.Job;
import org.gitlab4j.api.models.JobAttributes;

/**
* This class provides an entry point to all the GitLab API job calls.
Expand Down Expand Up @@ -532,9 +531,35 @@ public Job eraseJob(Object projectIdOrPath, Long jobId) throws GitLabApiExceptio
* @throws GitLabApiException if any exception occurs during execution
*/
public Job playJob(Object projectIdOrPath, Long jobId) throws GitLabApiException {
return playJob(projectIdOrPath, jobId, null);
}

/**
* Play specified job with parameters in a project.
*
* <pre>
* <code>GitLab Endpoint: POST /projects/:id/jobs/:job_id/play</code>
* </pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID
* or path
* @param jobId the ID to play job
* @param jobAttributes attributes for the played job
* @return job instance which just played
* @throws GitLabApiException if any exception occurs during execution
*/
public Job playJob(Object projectIdOrPath, Long jobId, JobAttributes jobAttributes)
throws GitLabApiException {
Response response;
if (jobAttributes == null) {
GitLabApiForm formData = null;
Response response = post(Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
return (response.readEntity(Job.class));
response = post(Status.CREATED, formData, "projects",
getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
} else {
response = post(Status.CREATED, jobAttributes, "projects",
getProjectIdOrPath(projectIdOrPath), "jobs", jobId, "play");
}
return (response.readEntity(Job.class));
}

/**
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/gitlab4j/api/models/JobAttribute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.gitlab4j.api.models;

import org.gitlab4j.api.utils.JacksonJson;

public class JobAttribute {

private String key;
private String value;

public JobAttribute(String key, String value) {
this.key = key;
this.value = value;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
28 changes: 28 additions & 0 deletions src/main/java/org/gitlab4j/api/models/JobAttributes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.gitlab4j.api.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import org.gitlab4j.api.utils.JacksonJson;

public class JobAttributes {

@JsonProperty("job_variables_attributes")
private List<JobAttribute> jobAttributes;

public JobAttributes(List<JobAttribute> jobAttributes) {
this.jobAttributes = jobAttributes;
}

public List<JobAttribute> getJobAttributes() {
return jobAttributes;
}

public void setJobAttributes(List<JobAttribute> jobAttributes) {
this.jobAttributes = jobAttributes;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}