Skip to content

Commit

Permalink
Merge pull request gitlab4j#726 from gitlab4j/issue-645-add-pipeline-…
Browse files Browse the repository at this point in the history
…id-in-commit-status

Fix gitlab4j#645 : Add pipeline_id in POST CommitStatus
  • Loading branch information
jabby authored Jul 5, 2021
2 parents 39de07d + 24b709f commit 0f413e2
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/main/java/org/gitlab4j/api/CommitsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public List<CommitStatus> getCommitStatuses(Object projectIdOrPath, String sha,

MultivaluedMap<String, String> queryParams = (filter != null ?
filter.getQueryParams(page, perPage).asMap() : getPageQueryParams(page, perPage));
Response response = get(Response.Status.OK, queryParams,
Response response = get(Response.Status.OK, queryParams,
"projects", this.getProjectIdOrPath(projectIdOrPath), "repository", "commits", sha, "statuses");
return (response.readEntity(new GenericType<List<CommitStatus>>() {}));
}
Expand All @@ -515,7 +515,7 @@ public List<CommitStatus> getCommitStatuses(Object projectIdOrPath, String sha,
* @return a Pager containing the commit statuses for the specified project and sha that meet the provided filter
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Pager<CommitStatus> getCommitStatuses(Object projectIdOrPath, String sha,
public Pager<CommitStatus> getCommitStatuses(Object projectIdOrPath, String sha,
CommitStatusFilter filter, int itemsPerPage) throws GitLabApiException {

if (projectIdOrPath == null) {
Expand Down Expand Up @@ -567,6 +567,31 @@ public Stream<CommitStatus> getCommitStatusesStream(Object projectIdOrPath, Stri
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public CommitStatus addCommitStatus(Object projectIdOrPath, String sha, CommitBuildState state, CommitStatus status) throws GitLabApiException {
return addCommitStatus(projectIdOrPath, sha, state, null, status);
}

/**
* <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>GitLab Endpoint: 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 pipelineId The ID of the pipeline to set status. Use in case of several pipeline on same SHA (optional)
* @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, Integer pipelineId, CommitStatus status) throws GitLabApiException {

if (projectIdOrPath == null) {
throw new RuntimeException("projectIdOrPath cannot be null");
Expand All @@ -585,6 +610,10 @@ public CommitStatus addCommitStatus(Object projectIdOrPath, String sha, CommitBu
.withParam("coverage", status.getCoverage());
}

if (pipelineId != null) {
formData.withParam("pipeline_id", pipelineId);
}

Response response = post(Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "statuses", sha);
return (response.readEntity(CommitStatus.class));
}
Expand Down Expand Up @@ -837,7 +866,7 @@ public Commit revertCommit(Object projectIdOrPath, String sha, String branch) th
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits", sha, "revert");
return (response.readEntity(Commit.class));
}

/**
* Cherry picks a commit in a given branch.
*
Expand Down

0 comments on commit 0f413e2

Please sign in to comment.