From 76150c65727b4dcb3b018066c5163e4c21b2f4cd Mon Sep 17 00:00:00 2001 From: jeroen wijdemans Date: Thu, 14 Dec 2017 08:32:38 +0100 Subject: [PATCH 1/2] Added support to list MergeRequests by state --- src/main/java/org/gitlab4j/api/Constants.java | 22 +++++++++++++++++++ .../org/gitlab4j/api/MergeRequestApi.java | 18 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/Constants.java b/src/main/java/org/gitlab4j/api/Constants.java index c4ce2ab3f..26a36f253 100644 --- a/src/main/java/org/gitlab4j/api/Constants.java +++ b/src/main/java/org/gitlab4j/api/Constants.java @@ -169,6 +169,28 @@ public String toString() { } } + /** Enum to use for querying the state of a MergeRequest */ + public enum MergeRequestState { + OPENED, CLOSED, MERGED, ALL; + + private static JacksonJsonEnumHelper enumHelper = new JacksonJsonEnumHelper<>(MergeRequestState.class); + + @JsonCreator + public static MergeRequestState forValue(String value) { return enumHelper.forValue(value); } + + + @JsonValue + public String toValue() { + return (enumHelper.toString(this)); + } + + @Override + public String toString() { + return (enumHelper.toString(this)); + } + } + + /** Enum to use for specifying the state of a merge request or issue update. */ public enum StateEvent { diff --git a/src/main/java/org/gitlab4j/api/MergeRequestApi.java b/src/main/java/org/gitlab4j/api/MergeRequestApi.java index a6776ac29..c61ac5977 100644 --- a/src/main/java/org/gitlab4j/api/MergeRequestApi.java +++ b/src/main/java/org/gitlab4j/api/MergeRequestApi.java @@ -78,6 +78,24 @@ public MergeRequest getMergeRequest(Integer projectId, Integer mergeRequestId) t return (response.readEntity(MergeRequest.class)); } + /** + * Get all merge requests with a specific state for the specified project. + * + * GET /projects/:id/merge_requests?state=:state + * + * @param projectId the project ID to get the merge requests for + * @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all). The pagination parameters page and per_page can be used to restrict the list of merge requests. + * @return all merge requests for the specified project + * @throws GitLabApiException if any exception occurs + */ + public List getMergeRequests(Integer projectId, MergeRequestState state) throws GitLabApiException { + Form formData = new GitLabApiForm() + .withParam("state", state) + .withParam(PER_PAGE_PARAM, getDefaultPerPage()); + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests"); + return (response.readEntity(new GenericType>() {})); + } + /** * Get a list of merge request commits. * From d7a915d7391b192cbf80536c98b04dd299e68414 Mon Sep 17 00:00:00 2001 From: Jeroen Wijdemans Date: Thu, 14 Dec 2017 13:35:48 +0100 Subject: [PATCH 2/2] Adding getMergeRequests by State with paging support Change-Id: I2cd4cf79e25de91d54acc966e03aaa91bc37c592 --- .../org/gitlab4j/api/MergeRequestApi.java | 57 ++++++++++++++++--- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/MergeRequestApi.java b/src/main/java/org/gitlab4j/api/MergeRequestApi.java index c61ac5977..cf296a249 100644 --- a/src/main/java/org/gitlab4j/api/MergeRequestApi.java +++ b/src/main/java/org/gitlab4j/api/MergeRequestApi.java @@ -64,18 +64,42 @@ public Pager getMergeRequests(Integer projectId, int itemsPerPage) } /** - * Get information about a single merge request. + * Get all merge requests for the specified project. * - * GET /projects/:id/merge_requests/:merge_request_id + * GET /projects/:id/merge_requests * - * @param projectId the project ID of the merge request - * @param mergeRequestId the ID of the merge request - * @return the specified MergeRequest instance + * @param projectId the project ID to get the merge requests for + * @param page the page to get + * @param perPage the number of MergeRequest instances per page + * @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all). + * @return all merge requests for the specified project * @throws GitLabApiException if any exception occurs */ - public MergeRequest getMergeRequest(Integer projectId, Integer mergeRequestId) throws GitLabApiException { - Response response = get(Response.Status.OK, null, "projects", projectId, "merge_requests", mergeRequestId); - return (response.readEntity(MergeRequest.class)); + public List getMergeRequests(Integer projectId, int page, int perPage, MergeRequestState state) throws GitLabApiException { + Form formData = new GitLabApiForm() + .withParam("state", state) + .withParam(PAGE_PARAM, page) + .withParam(PER_PAGE_PARAM, perPage); + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests"); + return (response.readEntity(new GenericType>() {})); + } + + + /** + * Get all merge requests for the specified project. + * + * GET /projects/:id/merge_requests + * + * @param projectId the project ID to get the merge requests for + * @param itemsPerPage the number of MergeRequest instances that will be fetched per page + * @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all). + * @return all merge requests for the specified project + * @throws GitLabApiException if any exception occurs + */ + public Pager getMergeRequests(Integer projectId, int itemsPerPage, MergeRequestState state) throws GitLabApiException { + Form formData = new GitLabApiForm() + .withParam("state", state); + return (new Pager(this, MergeRequest.class, itemsPerPage, formData.asMap(), "projects", projectId, "merge_requests")); } /** @@ -84,7 +108,7 @@ public MergeRequest getMergeRequest(Integer projectId, Integer mergeRequestId) t * GET /projects/:id/merge_requests?state=:state * * @param projectId the project ID to get the merge requests for - * @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all). The pagination parameters page and per_page can be used to restrict the list of merge requests. + * @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all). * @return all merge requests for the specified project * @throws GitLabApiException if any exception occurs */ @@ -96,6 +120,21 @@ public List getMergeRequests(Integer projectId, MergeRequestState return (response.readEntity(new GenericType>() {})); } + /** + * Get information about a single merge request. + * + * GET /projects/:id/merge_requests/:merge_request_id + * + * @param projectId the project ID of the merge request + * @param mergeRequestId the ID of the merge request + * @return the specified MergeRequest instance + * @throws GitLabApiException if any exception occurs + */ + public MergeRequest getMergeRequest(Integer projectId, Integer mergeRequestId) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "projects", projectId, "merge_requests", mergeRequestId); + return (response.readEntity(MergeRequest.class)); + } + /** * Get a list of merge request commits. *