Skip to content

Commit

Permalink
Added getCommits() methods for merge requests (#68).
Browse files Browse the repository at this point in the history
  • Loading branch information
gmessner committed Aug 27, 2017
1 parent 9f480b3 commit 14519fa
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/main/java/org/gitlab4j/api/MergeRequestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Commit> 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<Commit> 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<List<Commit>>() {}));
}

/**
* 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<Commit> getCommits(int projectId, int mergeRequestId, int itemsPerPage) throws GitLabApiException {
return (new Pager<Commit>(this, Commit.class, itemsPerPage, null,
"projects", projectId, "merge_request", mergeRequestId, "commits"));
}

/**
* Creates a merge request and optionally assigns a reviewer to it.
*
Expand Down

0 comments on commit 14519fa

Please sign in to comment.