@@ -363,6 +363,50 @@ public Pager<CommitStatus> getCommitStatuses(Object projectIdOrPath, String sha,
363363 "projects" , this .getProjectIdOrPath (projectIdOrPath ), "repository" , "commits" , sha , "statuses" ));
364364 }
365365
366+ /**
367+ * <p>Add or update the build status of a commit. The following fluent methods are available on the
368+ * CommitStatus instance for setting up the status:</p>
369+ * <pre><code>
370+ * withCoverage(Float)
371+ * withDescription(String)
372+ * withName(String)
373+ * withRef(String)
374+ * withTargetUrl(String)
375+ * </code></pre>
376+ * <pre><code>
377+ * POST /projects/:id/statuses/:sha
378+ * </code></pre>
379+ *
380+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance (required)
381+ * @param sha a commit SHA (required)
382+ * @param state the state of the status. Can be one of the following: PENDING, RUNNING, SUCCESS, FAILED, CANCELED (required)
383+ * @param status the CommitSatus instance hoilding the optional parms: ref, name, target_url, description, and coverage
384+ * @return a CommitStatus instance with the updated info
385+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
386+ */
387+ public CommitStatus addCommitStatus (Object projectIdOrPath , String sha , CommitBuildState state , CommitStatus status ) throws GitLabApiException {
388+
389+ if (projectIdOrPath == null ) {
390+ throw new RuntimeException ("projectIdOrPath cannot be null" );
391+ }
392+
393+ if (sha == null || sha .trim ().isEmpty ()) {
394+ throw new RuntimeException ("sha cannot be null" );
395+ }
396+
397+ GitLabApiForm formData = new GitLabApiForm ().withParam ("state" , state , true );
398+ if (status != null ) {
399+ formData .withParam ("ref" , status .getRef ())
400+ .withParam ("name" , status .getName ())
401+ .withParam ("target_url" , status .getTargetUrl ())
402+ .withParam ("description" , status .getDescription ())
403+ .withParam ("coverage" , status .getCoverage ());
404+ }
405+
406+ Response response = post (Response .Status .OK , formData , "projects" , getProjectIdOrPath (projectIdOrPath ), "statuses" , sha );
407+ return (response .readEntity (CommitStatus .class ));
408+ }
409+
366410 /**
367411 * Get the list of diffs of a commit in a project.
368412 *
0 commit comments