Skip to content

Commit 14519fa

Browse files
committed
Added getCommits() methods for merge requests (#68).
1 parent 9f480b3 commit 14519fa

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/main/java/org/gitlab4j/api/MergeRequestApi.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import javax.ws.rs.core.Response;
88

99
import org.gitlab4j.api.GitLabApi.ApiVersion;
10+
import org.gitlab4j.api.models.Commit;
1011
import org.gitlab4j.api.models.MergeRequest;
12+
import org.gitlab4j.api.utils.ISO8601;
1113

1214
/**
1315
* 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
7779
return (response.readEntity(MergeRequest.class));
7880
}
7981

82+
/**
83+
* Get a list of merge request commits.
84+
*
85+
* GET /projects/:id/merge_requests/:merge_request_iid/commits
86+
*
87+
* @param projectId the project ID for the merge request
88+
* @param mergeRequestId the ID of the merge request
89+
* @return a list containing the commits for the specified merge request
90+
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
91+
*/
92+
public List<Commit> getCommits(int projectId, int mergeRequestId) throws GitLabApiException {
93+
return (getCommits(projectId, mergeRequestId, 1, getDefaultPerPage()));
94+
}
95+
96+
/**
97+
* Get a list of merge request commits.
98+
*
99+
* GET /projects/:id/merge_requests/:merge_request_iid/commits
100+
*
101+
* @param projectId the project ID for the merge request
102+
* @param mergeRequestId the ID of the merge request
103+
* @param page the page to get
104+
* @param perPage the number of commits per page
105+
* @return a list containing the commits for the specified merge request
106+
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
107+
*/
108+
public List<Commit> getCommits(int projectId, int mergeRequestId, int page, int perPage) throws GitLabApiException {
109+
Form formData = new GitLabApiForm().withParam("owned", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
110+
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_request", mergeRequestId, "commits");
111+
return (response.readEntity(new GenericType<List<Commit>>() {}));
112+
}
113+
114+
/**
115+
* Get a Pager of merge request commits.
116+
*
117+
* GET /projects/:id/merge_requests/:merge_request_iid/commits
118+
*
119+
* @param projectId the project ID for the merge request
120+
* @param mergeRequestId the ID of the merge request
121+
* @param itemsPerPage the number of Commit instances that will be fetched per page
122+
* @return a Pager containing the commits for the specified merge request
123+
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
124+
*/
125+
public Pager<Commit> getCommits(int projectId, int mergeRequestId, int itemsPerPage) throws GitLabApiException {
126+
return (new Pager<Commit>(this, Commit.class, itemsPerPage, null,
127+
"projects", projectId, "merge_request", mergeRequestId, "commits"));
128+
}
129+
80130
/**
81131
* Creates a merge request and optionally assigns a reviewer to it.
82132
*

0 commit comments

Comments
 (0)