From 14519fae2517469a137be3e3643d9630ec24fb35 Mon Sep 17 00:00:00 2001 From: Greg Messner Date: Sat, 26 Aug 2017 20:17:15 -0700 Subject: [PATCH] Added getCommits() methods for merge requests (#68). --- .../org/gitlab4j/api/MergeRequestApi.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/MergeRequestApi.java b/src/main/java/org/gitlab4j/api/MergeRequestApi.java index ae9737fb3..e743dfcd9 100644 --- a/src/main/java/org/gitlab4j/api/MergeRequestApi.java +++ b/src/main/java/org/gitlab4j/api/MergeRequestApi.java @@ -7,7 +7,9 @@ import javax.ws.rs.core.Response; import org.gitlab4j.api.GitLabApi.ApiVersion; +import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.MergeRequest; +import org.gitlab4j.api.utils.ISO8601; /** * This class implements the client side API for the GitLab merge request calls. @@ -77,6 +79,54 @@ public MergeRequest getMergeRequest(Integer projectId, Integer mergeRequestId) t return (response.readEntity(MergeRequest.class)); } + /** + * Get a list of merge request commits. + * + * GET /projects/:id/merge_requests/:merge_request_iid/commits + * + * @param projectId the project ID for the merge request + * @param mergeRequestId the ID of the merge request + * @return a list containing the commits for the specified merge request + * @throws GitLabApiException GitLabApiException if any exception occurs during execution + */ + public List getCommits(int projectId, int mergeRequestId) throws GitLabApiException { + return (getCommits(projectId, mergeRequestId, 1, getDefaultPerPage())); + } + + /** + * Get a list of merge request commits. + * + * GET /projects/:id/merge_requests/:merge_request_iid/commits + * + * @param projectId the project ID for the merge request + * @param mergeRequestId the ID of the merge request + * @param page the page to get + * @param perPage the number of commits per page + * @return a list containing the commits for the specified merge request + * @throws GitLabApiException GitLabApiException if any exception occurs during execution + */ + public List getCommits(int projectId, int mergeRequestId, int page, int perPage) throws GitLabApiException { + Form formData = new GitLabApiForm().withParam("owned", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage); + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_request", mergeRequestId, "commits"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get a Pager of merge request commits. + * + * GET /projects/:id/merge_requests/:merge_request_iid/commits + * + * @param projectId the project ID for the merge request + * @param mergeRequestId the ID of the merge request + * @param itemsPerPage the number of Commit instances that will be fetched per page + * @return a Pager containing the commits for the specified merge request + * @throws GitLabApiException GitLabApiException if any exception occurs during execution + */ + public Pager getCommits(int projectId, int mergeRequestId, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, Commit.class, itemsPerPage, null, + "projects", projectId, "merge_request", mergeRequestId, "commits")); + } + /** * Creates a merge request and optionally assigns a reviewer to it. *