From 24b709f4dd5e7ed8aa98d4ffb3ccda4981152095 Mon Sep 17 00:00:00 2001 From: Gautier de Saint Martin Lacaze Date: Mon, 5 Jul 2021 16:13:36 +0200 Subject: [PATCH] Fix #645 : Add pipeline_id in POST CommitStatus --- .../java/org/gitlab4j/api/CommitsApi.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/CommitsApi.java b/src/main/java/org/gitlab4j/api/CommitsApi.java index 9fcdb18b3..eaaaaa05d 100644 --- a/src/main/java/org/gitlab4j/api/CommitsApi.java +++ b/src/main/java/org/gitlab4j/api/CommitsApi.java @@ -498,7 +498,7 @@ public List getCommitStatuses(Object projectIdOrPath, String sha, MultivaluedMap 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>() {})); } @@ -515,7 +515,7 @@ public List 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 getCommitStatuses(Object projectIdOrPath, String sha, + public Pager getCommitStatuses(Object projectIdOrPath, String sha, CommitStatusFilter filter, int itemsPerPage) throws GitLabApiException { if (projectIdOrPath == null) { @@ -567,6 +567,31 @@ public Stream 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); + } + + /** + *

Add or update the build status of a commit. The following fluent methods are available on the + * CommitStatus instance for setting up the status:

+ *

+     * withCoverage(Float)
+     * withDescription(String)
+     * withName(String)
+     * withRef(String)
+     * withTargetUrl(String)
+     * 
+ * + *
GitLab Endpoint: POST /projects/:id/statuses/:sha
+ * + * @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"); @@ -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)); } @@ -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. *