From a30b49e706119ca14d9c904602cb0ca1f947d7fe Mon Sep 17 00:00:00 2001 From: David Lam Date: Mon, 30 Apr 2018 00:36:26 -0400 Subject: [PATCH] Controlled Pagination for Runners --- .../java/org/gitlab4j/api/RunnersApi.java | 74 +++++++++++++++++-- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/RunnersApi.java b/src/main/java/org/gitlab4j/api/RunnersApi.java index 058ebb038..1e42a4d96 100644 --- a/src/main/java/org/gitlab4j/api/RunnersApi.java +++ b/src/main/java/org/gitlab4j/api/RunnersApi.java @@ -26,11 +26,11 @@ public RunnersApi(GitLabApi gitLabApi) { * @throws GitLabApiException if any exception occurs */ public List getRunners() throws GitLabApiException { - return getRunners(null); + return getRunners(null, null, null); } /** - * Get a list of specific runners available to the user. + * Get a list of all available runners available to the user with pagination support. * * GET /runners * @@ -39,8 +39,39 @@ public List getRunners() throws GitLabApiException { * @throws GitLabApiException if any exception occurs */ public List getRunners(Runner.RunnerStatus scope) throws GitLabApiException { + return getRunners(scope, null, null); + } + + /** + * Get a list of all available runners available to the user with pagination support. + * + * GET /runners + * + * @param page The page offset of runners + * @param perPage The number of runners to get after the page offset + * @return List of Runners + * @throws GitLabApiException if any exception occurs + */ + public List getRunners(int page, int perPage) throws GitLabApiException { + return getRunners(null, page, perPage); + } + + /** + * Get a list of specific runners available to the user. + * + * GET /runners + * + * @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null + * @param page The page offset of runners + * @param perPage The number of runners to get after the page offset + * @return List of Runners + * @throws GitLabApiException if any exception occurs + */ + public List getRunners(Runner.RunnerStatus scope, Integer page, Integer perPage) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() - .withParam("scope", scope, false); + .withParam("scope", scope, false) + .withParam("page", page, false) + .withParam("per_page", perPage, false); Response response = get(Response.Status.OK, formData.asMap(), "runners"); return (response.readEntity(new GenericType>() { })); @@ -84,7 +115,7 @@ public Pager getRunners(Runner.RunnerStatus scope, int itemsPerPage) thr * @throws GitLabApiException if any exception occurs */ public List getAllRunners() throws GitLabApiException { - return getAllRunners(null); + return getAllRunners(null, null, null); } /** @@ -97,8 +128,38 @@ public List getAllRunners() throws GitLabApiException { * @throws GitLabApiException if any exception occurs */ public List getAllRunners(Runner.RunnerStatus scope) throws GitLabApiException { + return getAllRunners(scope, null, null); + } + + /** + * Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges. + * + * GET /runners/all + * + * @param page The page offset of runners + * @param perPage The number of runners to get after the page offset * @return List of Runners + * @throws GitLabApiException if any exception occurs + */ + public List getAllRunners(int page, int perPage) throws GitLabApiException { + return getAllRunners(null, page, perPage); + } + + /** + * Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges. + * + * GET /runners/all + * + * @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null + * @param page The page offset of runners + * @param perPage The number of runners to get after the page offset + * @return List of Runners + * @throws GitLabApiException if any exception occurs + */ + public List getAllRunners(Runner.RunnerStatus scope, Integer page, Integer perPage) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() - .withParam("scope", scope, false); + .withParam("scope", scope, false) + .withParam("page", page, false) + .withParam("per_page", perPage, false); Response response = get(Response.Status.OK, formData.asMap(), "runners", "all"); return (response.readEntity(new GenericType>() { })); @@ -133,6 +194,7 @@ public Pager getAllRunners(Runner.RunnerStatus scope, int itemsPerPage) return (new Pager<>(this, Runner.class, itemsPerPage, formData.asMap(), "runners")); } + /** * Get details of a runner. * @@ -296,7 +358,7 @@ public List getProjectRunners(Integer projectId) throws GitLabApiExcepti * * GET /projects/:id/runners * - * @param projectId The ID of the project owned by the authenticated user + * @param projectId The ID of the project owned by the authenticated user * @param itemsPerPage the number of Project instances that will be fetched per page * @return Pager of all Runner available in the project * @throws GitLabApiException if any exception occurs