Commit c292eb75 authored by Jeroen Wijdemans's avatar Jeroen Wijdemans Committed by Greg Messner
Browse files

Added support to list MergeRequests by state (#110)

* Added support to list MergeRequests by state
* Added getMergeRequests by State with paging support
parent 9fe4c516
......@@ -169,6 +169,28 @@ public interface Constants {
}
}
/** Enum to use for querying the state of a MergeRequest */
public enum MergeRequestState {
OPENED, CLOSED, MERGED, ALL;
private static JacksonJsonEnumHelper<MergeRequestState> 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 {
......
......@@ -63,6 +63,63 @@ public class MergeRequestApi extends AbstractApi {
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, null, "projects", projectId, "merge_requests"));
}
/**
* 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 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 List<MergeRequest> 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<List<MergeRequest>>() {}));
}
/**
* 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<MergeRequest> getMergeRequests(Integer projectId, int itemsPerPage, MergeRequestState state) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("state", state);
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(), "projects", projectId, "merge_requests"));
}
/**
* 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).
* @return all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> 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<List<MergeRequest>>() {}));
}
/**
* Get information about a single merge request.
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment