Skip to content

Commit

Permalink
Support include_retried when getting jobs for a pipeline via paging (#…
Browse files Browse the repository at this point in the history
…1046)

Follow-up to #954, which added the same for the non-paging request already.

If pipelines have a large amount of jobs (> 100 at least), need to use
the paging API to get all jobs (as GitLab limits paging size to max. 100).
JobApi didn't support the include_retried flag yet, in the methods that
support paging (i.e. those that return Pager<Job>/Stream<Job>)
  • Loading branch information
s-rwe authored Oct 31, 2023
1 parent 1b3763e commit 7646876
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/main/java/org/gitlab4j/api/JobApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,27 @@ public List<Job> getJobsForPipeline(Object projectIdOrPath, long pipelineId, Job
* @throws GitLabApiException if any exception occurs during execution
*/
public Pager<Job> getJobsForPipeline(Object projectIdOrPath, long pipelineId, int itemsPerPage) throws GitLabApiException {
return (new Pager<Job>(this, Job.class, itemsPerPage, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId, "jobs"));
return getJobsForPipeline(projectIdOrPath, pipelineId, itemsPerPage, null);
}

/**
* Get a Pager of jobs in a pipeline.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines/:pipeline_id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the pipelines for
* @param pipelineId the pipeline ID to get the list of jobs for
* @param itemsPerPage the number of Job instances that will be fetched per page
* @param includeRetried Include retried jobs in the response
* @return a list containing the jobs for the specified project ID and pipeline ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Pager<Job> getJobsForPipeline(Object projectIdOrPath, long pipelineId, int itemsPerPage, Boolean includeRetried) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("include_retried", includeRetried)
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
return (new Pager<Job>(this, Job.class, itemsPerPage, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId, "jobs"));
}

/**
Expand All @@ -222,6 +241,20 @@ public Stream<Job> getJobsStream(Object projectIdOrPath, long pipelineId) throws
return (getJobsForPipeline(projectIdOrPath, pipelineId, getDefaultPerPage()).stream());
}

/**
* Get a Stream of jobs in a pipeline.
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines/:pipeline_id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param pipelineId the pipeline ID to get the list of jobs for
* @param includeRetried Include retried jobs in the response
* @return a Stream containing the jobs for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Stream<Job> getJobsStream(Object projectIdOrPath, long pipelineId, Boolean includeRetried) throws GitLabApiException {
return (getJobsForPipeline(projectIdOrPath, pipelineId, getDefaultPerPage(), includeRetried).stream());
}

/**
* Get single job in a project.
*
Expand Down

0 comments on commit 7646876

Please sign in to comment.