Skip to content

Commit 4557a2b

Browse files
authored
Add methods to retrieve Merge Requests with projectIdOrPath and filter (#1275)
1 parent 7bd1d19 commit 4557a2b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,52 @@ public List<MergeRequest> getMergeRequests(Object projectIdOrPath) throws GitLab
155155
return (getMergeRequests(projectIdOrPath, getDefaultPerPage()).all());
156156
}
157157

158+
/**
159+
* Get all merge requests for the specified project.
160+
*
161+
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests</code></pre>
162+
*
163+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
164+
* @param filter a MergeRequestFilter instance with the filter settings
165+
* @return all merge requests for the specified project matching the filter
166+
* @throws GitLabApiException if any exception occurs
167+
*/
168+
public List<MergeRequest> getMergeRequests(Object projectIdOrPath, MergeRequestFilter filter)
169+
throws GitLabApiException {
170+
return (getMergeRequests(projectIdOrPath, filter, getDefaultPerPage()).all());
171+
}
172+
173+
/**
174+
* Get all merge requests for the specified project.
175+
*
176+
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests</code></pre>
177+
*
178+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
179+
* @param filter a MergeRequestFilter instance with the filter settings
180+
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
181+
* @return all merge requests for the specified project matching the filter
182+
* @throws GitLabApiException if any exception occurs
183+
*/
184+
public Pager<MergeRequest> getMergeRequests(Object projectIdOrPath, MergeRequestFilter filter, int itemsPerPage)
185+
throws GitLabApiException {
186+
187+
if (filter != null && filter.getProjectId() != null) {
188+
throw new RuntimeException(
189+
"projectId cannot be specified in filter, use projectIdOrPath parameter instead");
190+
}
191+
192+
MultivaluedMap<String, String> queryParams =
193+
(filter != null ? new GitLabApiForm(filter.getQueryParams()).asMap() : null);
194+
return (new Pager<MergeRequest>(
195+
this,
196+
MergeRequest.class,
197+
itemsPerPage,
198+
queryParams,
199+
"projects",
200+
getProjectIdOrPath(projectIdOrPath),
201+
"merge_requests"));
202+
}
203+
158204
/**
159205
* Get all merge requests for the specified project.
160206
*

0 commit comments

Comments
 (0)