Skip to content

Commit 7646876

Browse files
authored
Support include_retried when getting jobs for a pipeline via paging (gitlab4j#1046)
Follow-up to gitlab4j#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>)
1 parent 1b3763e commit 7646876

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/main/java/org/gitlab4j/api/JobApi.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,27 @@ public List<Job> getJobsForPipeline(Object projectIdOrPath, long pipelineId, Job
205205
* @throws GitLabApiException if any exception occurs during execution
206206
*/
207207
public Pager<Job> getJobsForPipeline(Object projectIdOrPath, long pipelineId, int itemsPerPage) throws GitLabApiException {
208-
return (new Pager<Job>(this, Job.class, itemsPerPage, getDefaultPerPageParam(),
209-
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId, "jobs"));
208+
return getJobsForPipeline(projectIdOrPath, pipelineId, itemsPerPage, null);
209+
}
210+
211+
/**
212+
* Get a Pager of jobs in a pipeline.
213+
*
214+
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines/:pipeline_id/jobs</code></pre>
215+
*
216+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the pipelines for
217+
* @param pipelineId the pipeline ID to get the list of jobs for
218+
* @param itemsPerPage the number of Job instances that will be fetched per page
219+
* @param includeRetried Include retried jobs in the response
220+
* @return a list containing the jobs for the specified project ID and pipeline ID
221+
* @throws GitLabApiException if any exception occurs during execution
222+
*/
223+
public Pager<Job> getJobsForPipeline(Object projectIdOrPath, long pipelineId, int itemsPerPage, Boolean includeRetried) throws GitLabApiException {
224+
GitLabApiForm formData = new GitLabApiForm()
225+
.withParam("include_retried", includeRetried)
226+
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
227+
return (new Pager<Job>(this, Job.class, itemsPerPage, formData.asMap(),
228+
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId, "jobs"));
210229
}
211230

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

244+
/**
245+
* Get a Stream of jobs in a pipeline.
246+
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines/:pipeline_id/jobs</code></pre>
247+
*
248+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
249+
* @param pipelineId the pipeline ID to get the list of jobs for
250+
* @param includeRetried Include retried jobs in the response
251+
* @return a Stream containing the jobs for the specified project ID
252+
* @throws GitLabApiException if any exception occurs during execution
253+
*/
254+
public Stream<Job> getJobsStream(Object projectIdOrPath, long pipelineId, Boolean includeRetried) throws GitLabApiException {
255+
return (getJobsForPipeline(projectIdOrPath, pipelineId, getDefaultPerPage(), includeRetried).stream());
256+
}
257+
225258
/**
226259
* Get single job in a project.
227260
*

0 commit comments

Comments
 (0)