Skip to content

Added possibility to get only first page from project's pipelines #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/org/gitlab/api/GitlabAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,18 @@ public List<GitlabPipeline> getProjectPipelines(Integer projectId, PipelinesQuer
return retrieve().getAll(tailUrl, GitlabPipeline[].class);
}

/**
* Get the first page of project's pipelines in Gitlab.
*
* @param projectId the project id
* @return A list of project pipelines
*/
public List<GitlabPipeline> getFirstProjectPipelinePage(Integer projectId, PipelinesQuery pipelinesQuery) {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabPipeline.URL + pipelinesQuery;
return retrieve().getFirstPage(tailUrl, GitlabPipeline[].class);
}


/**
* Gets a list of a project's jobs in Gitlab
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ public <T> List<T> getAll(final String tailUrl, final Class<T[]> type) {
return results;
}

public <T> List<T> getFirstPage(final String tailUrl, final Class<T[]> type) {
Iterator<T[]> iterator = asIterator(tailUrl, type);
if (iterator.hasNext()) {
T[] requests = iterator.next();
if (requests.length > 0) {
return Arrays.asList(requests);
}
}
return new ArrayList<>();
}

public <T> Iterator<T> asIterator(final String tailApiUrl, final Class<T> type) {
method(GET); // Ensure we only use iterators for GET requests

Expand Down