Commit 437b75a9 authored by Greg Messner's avatar Greg Messner
Browse files

Mods to support addCommitStatus() (#274).

parent f93b15dd
......@@ -363,6 +363,50 @@ public class CommitsApi extends AbstractApi {
"projects", this.getProjectIdOrPath(projectIdOrPath), "repository", "commits", sha, "statuses"));
}
/**
* <p>Add or update the build status of a commit. The following fluent methods are available on the
* CommitStatus instance for setting up the status:</p>
* <pre><code>
* withCoverage(Float)
* withDescription(String)
* withName(String)
* withRef(String)
* withTargetUrl(String)
* </code></pre>
* <pre><code>
* POST /projects/:id/statuses/:sha
* </code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance (required)
* @param sha a commit SHA (required)
* @param state the state of the status. Can be one of the following: PENDING, RUNNING, SUCCESS, FAILED, CANCELED (required)
* @param status the CommitSatus instance hoilding the optional parms: ref, name, target_url, description, and coverage
* @return a CommitStatus instance with the updated info
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public CommitStatus addCommitStatus(Object projectIdOrPath, String sha, CommitBuildState state, CommitStatus status) throws GitLabApiException {
if (projectIdOrPath == null) {
throw new RuntimeException("projectIdOrPath cannot be null");
}
if (sha == null || sha.trim().isEmpty()) {
throw new RuntimeException("sha cannot be null");
}
GitLabApiForm formData = new GitLabApiForm().withParam("state", state, true);
if (status != null) {
formData.withParam("ref", status.getRef())
.withParam("name", status.getName())
.withParam("target_url", status.getTargetUrl())
.withParam("description", status.getDescription())
.withParam("coverage", status.getCoverage());
}
Response response = post(Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "statuses", sha);
return (response.readEntity(CommitStatus.class));
}
/**
* Get the list of diffs of a commit in a project.
*
......
......@@ -501,4 +501,29 @@ public interface Constants {
return (value);
}
}
/**
* Enum for the various Commit build status values.
*/
public enum CommitBuildState {
PENDING, RUNNING, SUCCESS, FAILED, CANCELED;
private static JacksonJsonEnumHelper<CommitBuildState> enumHelper = new JacksonJsonEnumHelper<>(CommitBuildState.class);
@JsonCreator
public static CommitBuildState forValue(String value) {
return enumHelper.forValue(value);
}
@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}
@Override
public String toString() {
return (enumHelper.toString(this));
}
}
}
......@@ -13,6 +13,7 @@ public class CommitStatus {
private Boolean allowFailure;
private Author author;
private Float coverage;
private Date createdAt;
private String description;
private Date finishedAt;
......@@ -40,6 +41,14 @@ public class CommitStatus {
this.author = author;
}
public Float getCoverage() {
return coverage;
}
public void setCoverage(Float coverage) {
this.coverage = coverage;
}
public Date getCreatedAt() {
return createdAt;
}
......@@ -119,4 +128,29 @@ public class CommitStatus {
public void setTargetUrl(String targetUrl) {
this.targetUrl = targetUrl;
}
public CommitStatus withCoverage(Float coverage) {
this.coverage = coverage;
return this;
}
public CommitStatus withDescription(String description) {
this.description = description;
return this;
}
public CommitStatus withName(String name) {
this.name = name;
return this;
}
public CommitStatus withRef(String ref) {
this.ref = ref;
return this;
}
public CommitStatus withTargetUrl(String targetUrl) {
this.targetUrl = targetUrl;
return this;
}
}
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