1111import org .gitlab4j .api .models .Pipeline ;
1212import org .gitlab4j .api .models .PipelineSchedule ;
1313import org .gitlab4j .api .models .PipelineStatus ;
14+ import org .gitlab4j .api .models .Trigger ;
1415import org .gitlab4j .api .models .Variable ;
1516
1617/**
17- * This class provides an entry point to all the GitLab API pipeline calls.
18+ * <p>This class provides an entry point to all the GitLab API pipeline related calls.
19+ * For more information on the Pipeline APIs see:</p>
20+ *
21+ * <a href="https://docs.gitlab.com/ee/api/pipelines.html">Pipelines API</a>
22+ * <a href="https://docs.gitlab.com/ee/api/pipeline_schedules.html">Pipeline Schedules API</a>
23+ * <a href="https://docs.gitlab.com/ee/api/pipeline_triggers.html">Pipeline Triggers API</a>
1824 */
1925public class PipelineApi extends AbstractApi implements Constants {
2026
@@ -314,7 +320,7 @@ public List<PipelineSchedule> getPipelineSchedules(Object projectIdOrPath) throw
314320 *
315321 * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
316322 * @param page the page to get
317- * @param perPage the number of ProjectHook instances per page
323+ * @param perPage the number of PipelineSchedule instances per page
318324 * @return a list of project pipeline_schedules for the specified project in the specified page range
319325 * @throws GitLabApiException if any exception occurs
320326 */
@@ -329,7 +335,7 @@ public List<PipelineSchedule> getPipelineSchedules(Object projectIdOrPath, int p
329335 * <pre><code>GET /projects/:id/pipeline_schedule</code></pre>
330336 *
331337 * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
332- * @param itemsPerPage the number of Project instances that will be fetched per page
338+ * @param itemsPerPage the number of PipelineSchedule instances that will be fetched per page
333339 * @return a Pager of project pipeline_schedules for the specified project
334340 * @throws GitLabApiException if any exception occurs
335341 */
@@ -356,8 +362,8 @@ public Stream<PipelineSchedule> getPipelineSchedulesStream(Object projectIdOrPat
356362 * <pre><code>GET /projects/:id/pipeline_schedules/:pipeline_schedule_id</code></pre>
357363 *
358364 * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
359- * @param pipelineScheduleId the ID of the hook to get
360- * @return the project hook for the specified project ID/hook ID pair
365+ * @param pipelineScheduleId the ID of the pipeline schedule to get
366+ * @return the project PipelineSchedule
361367 * @throws GitLabApiException if any exception occurs
362368 */
363369 public PipelineSchedule getPipelineSchedule (Object projectIdOrPath , Integer pipelineScheduleId ) throws GitLabApiException {
@@ -372,7 +378,7 @@ public PipelineSchedule getPipelineSchedule(Object projectIdOrPath, Integer pipe
372378 *
373379 * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
374380 * @param pipelineScheduleId the ID of the hook to get
375- * @return the project hook for the specified project ID/hook ID pair as an Optional instance
381+ * @return the project PipelineSchedule as an Optional instance
376382 */
377383 public Optional <PipelineSchedule > getOptionalPipelineSchedule (Object projectIdOrPath , Integer pipelineScheduleId ) {
378384 try {
@@ -517,4 +523,197 @@ public void deletePipelineScheduleVariable(Object projectIdOrPath, Integer pipel
517523 delete (expectedStatus , null , "projects" , getProjectIdOrPath (projectIdOrPath ),
518524 "pipeline_schedules" , pipelineScheduleId , "variables" , key );
519525 }
526+
527+ /**
528+ * Get a list of the project pipeline triggers for the specified project.
529+ *
530+ * <pre><code>GET /projects/:id/triggers</code></pre>
531+ *
532+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
533+ * @return a list of pipeline triggers for the specified project
534+ * @throws GitLabApiException if any exception occurs
535+ */
536+ public List <Trigger > getPipelineTriggers (Object projectIdOrPath ) throws GitLabApiException {
537+ return (getPipelineTriggers (projectIdOrPath , getDefaultPerPage ()).all ());
538+ }
539+
540+ /**
541+ * Get list of project pipeline triggers in the specified page range.
542+ *
543+ * <pre><code>GET /projects/:id/triggers</code></pre>
544+ *
545+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
546+ * @param page the page to get
547+ * @param perPage the number of Trigger instances per page
548+ * @return a list of project pipeline triggers for the specified project in the specified page range
549+ * @throws GitLabApiException if any exception occurs
550+ */
551+ public List <Trigger > getPipelineTriggerss (Object projectIdOrPath , int page , int perPage ) throws GitLabApiException {
552+ Response response = get (Response .Status .OK , getPageQueryParams (page , perPage ), "projects" , getProjectIdOrPath (projectIdOrPath ), "triggers" );
553+ return (response .readEntity (new GenericType <List <Trigger >>() {}));
554+ }
555+
556+ /**
557+ * Get Pager of project pipeline triggers.
558+ *
559+ * <pre><code>GET /projects/:id/pipeline_schedule</code></pre>
560+ *
561+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
562+ * @param itemsPerPage the number of Project instances that will be fetched per page
563+ * @return a Pager of project pipeline triggers for the specified project
564+ * @throws GitLabApiException if any exception occurs
565+ */
566+ public Pager <Trigger > getPipelineTriggers (Object projectIdOrPath , int itemsPerPage ) throws GitLabApiException {
567+ return (new Pager <Trigger >(this , Trigger .class , itemsPerPage , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "triggers" ));
568+ }
569+
570+ /**
571+ * Get a Stream of the project pipeline triggers for the specified project.
572+ *
573+ * <pre><code>GET /projects/:id/pipeline_schedule</code></pre>
574+ *
575+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
576+ * @return a Stream of project pipeline triggers for the specified project
577+ * @throws GitLabApiException if any exception occurs
578+ */
579+ public Stream <Trigger > getPipelineTriggersStream (Object projectIdOrPath ) throws GitLabApiException {
580+ return (getPipelineTriggers (projectIdOrPath , getDefaultPerPage ()).stream ());
581+ }
582+
583+ /**
584+ * Get a specific pipeline schedule for project.
585+ *
586+ * <pre><code>GET /projects/:id/triggers/:trigger_id</code></pre>
587+ *
588+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
589+ * @param triggerId the ID of the trigger to get
590+ * @return the project pipeline trigger
591+ * @throws GitLabApiException if any exception occurs
592+ */
593+ public Trigger getPipelineTrigger (Object projectIdOrPath , Integer triggerId ) throws GitLabApiException {
594+ Response response = get (Response .Status .OK , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "triggers" , triggerId );
595+ return (response .readEntity (Trigger .class ));
596+ }
597+
598+ /**
599+ * Get a specific pipeline trigger for project as an Optional instance.
600+ *
601+ * <pre><code>GET /projects/:id/triggers/:trigger_id</code></pre>
602+ *
603+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
604+ * @param triggerId the ID of the trigger to get
605+ * @return the project pipeline trigger as an Optional instance
606+ */
607+ public Optional <Trigger > getOptionalPipelineTrigger (Object projectIdOrPath , Integer triggerId ) {
608+ try {
609+ return (Optional .ofNullable (getPipelineTrigger (projectIdOrPath , triggerId )));
610+ } catch (GitLabApiException glae ) {
611+ return (GitLabApi .createOptionalFromException (glae ));
612+ }
613+ }
614+
615+ /**
616+ * Create a pipeline trigger for a project.
617+ *
618+ * <pre><code>POST /projects/:id/triggers</code></pre>
619+ *
620+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
621+ * @param description the trigger description
622+ * @return the created Trigger instance
623+ * @throws GitLabApiException if any exception occurs
624+ */
625+ public Trigger createPipelineTrigger (Object projectIdOrPath , String description ) throws GitLabApiException {
626+ GitLabApiForm formData = new GitLabApiForm ().withParam ("description" , description , true );
627+ Response response = post (Response .Status .CREATED , formData , "projects" , getProjectIdOrPath (projectIdOrPath ), "triggers" );
628+ return (response .readEntity (Trigger .class ));
629+ }
630+
631+ /**
632+ * Updates a pipeline trigger for project.
633+ *
634+ * <pre><code>PUT /projects/:id/triggers/:trigger_id</code></pre>
635+ *
636+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
637+ * @param triggerId the trigger ID to update
638+ * @param description the new trigger description
639+ * @return the updated Trigger instance
640+ * @throws GitLabApiException if any exception occurs
641+ */
642+ public Trigger updatePipelineTrigger (Object projectIdOrPath , Integer triggerId , String description ) throws GitLabApiException {
643+ GitLabApiForm formData = new GitLabApiForm ().withParam ("description" , description , false );
644+ Response response = put (Response .Status .OK , formData .asMap (), "projects" , getProjectIdOrPath (projectIdOrPath ), "triggers" , triggerId );
645+ return (response .readEntity (Trigger .class ));
646+ }
647+
648+ /**
649+ * Deletes a pipeline trigger from the project.
650+ *
651+ * <pre><code>DELETE /projects/:id/triggers/:trigger_id</code></pre>
652+ *
653+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
654+ * @param triggerId the project trigger ID to delete
655+ * @throws GitLabApiException if any exception occurs
656+ */
657+ public void deletePipelineTrigger (Object projectIdOrPath , Integer triggerId ) throws GitLabApiException {
658+ delete (Response .Status .NO_CONTENT , null , "projects" , getProjectIdOrPath (projectIdOrPath ), "triggers" , triggerId );
659+ }
660+
661+ /**
662+ * Take ownership of a pipeline trigger for project.
663+ *
664+ * <pre><code>PUT /projects/:id/triggers/:trigger_id/take_ownership</code></pre>
665+ *
666+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
667+ * @param triggerId the trigger ID to take opwnership of
668+ * @return the updated Trigger instance
669+ * @throws GitLabApiException if any exception occurs
670+ */
671+ public Trigger takeOwnewrshipOfPipelineTrigger (Object projectIdOrPath , Integer triggerId ) throws GitLabApiException {
672+ Response response = put (Response .Status .OK , null ,
673+ "projects" , getProjectIdOrPath (projectIdOrPath ), "triggers" , triggerId , "take_ownership" );
674+ return (response .readEntity (Trigger .class ));
675+ }
676+
677+ /**
678+ * Trigger a pipeline for a project.
679+ *
680+ * <pre><code>POST /projects/:id/trigger/pipeline</code></pre>
681+ *
682+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
683+ * @param trigger the Trigger instance holding the trigger token
684+ * @param ref the ref that the pipeline is to be triggered for
685+ * @param variables a List of variables to be passed with the trigger
686+ * @return a Pipeline instance holding information on the triggered pipeline
687+ * @throws GitLabApiException if any exception occurs
688+ */
689+ public Pipeline triggerPipeline (Object projectIdOrPath , Trigger trigger , String ref , List <Variable > variables ) throws GitLabApiException {
690+
691+ if (trigger == null ) {
692+ throw new GitLabApiException ("trigger cannot be null" );
693+ }
694+
695+ return (triggerPipeline (projectIdOrPath , trigger .getToken (), ref , variables ));
696+ }
697+
698+ /**
699+ * Trigger a pipeline for a project.
700+ *
701+ * <pre><code>POST /projects/:id/trigger/pipeline</code></pre>
702+ *
703+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
704+ * @param token the trigger token
705+ * @param ref the ref that the pipeline is to be triggered for
706+ * @param variables a List of variables to be passed with the trigger
707+ * @return a Pipeline instance holding information on the triggered pipeline
708+ * @throws GitLabApiException if any exception occurs
709+ */
710+ public Pipeline triggerPipeline (Object projectIdOrPath , String token , String ref , List <Variable > variables ) throws GitLabApiException {
711+ GitLabApiForm formData = new GitLabApiForm ()
712+ .withParam ("token" , token , true )
713+ .withParam ("ref" , ref , true )
714+ .withParam (variables );
715+ Response response = post (Response .Status .CREATED , formData ,
716+ "projects" , getProjectIdOrPath (projectIdOrPath ), "trigger" , "pipeline" );
717+ return (response .readEntity (Pipeline .class ));
718+ }
520719}
0 commit comments