Commit 5e57e9fb authored by Greg Messner's avatar Greg Messner
Browse files

Added support fopr filtering when fetching merge requests (#187, #193).

parent 677dcf36
...@@ -104,6 +104,29 @@ public interface Constants { ...@@ -104,6 +104,29 @@ public interface Constants {
} }
} }
/** Enum to use for ordering the results of getMergeRequests(). */
public enum MergeRequestOrderBy {
CREATED_AT, UPDATED_AT;
private static JacksonJsonEnumHelper<MergeRequestOrderBy> enumHelper = new JacksonJsonEnumHelper<>(MergeRequestOrderBy.class);
@JsonCreator
public static MergeRequestOrderBy 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 ordering the results of getGroups() and getSubGroups(). */ /** Enum to use for ordering the results of getGroups() and getSubGroups(). */
public enum GroupOrderBy { public enum GroupOrderBy {
...@@ -191,6 +214,27 @@ public interface Constants { ...@@ -191,6 +214,27 @@ public interface Constants {
} }
} }
/** Enum to use for specifying the scope for getMergeRequests methods. */
public enum MergeRequestScope {
CREATED_BY_ME, ASSIGNED_TO_ME, ALL;
private static JacksonJsonEnumHelper<MergeRequestScope> enumHelper = new JacksonJsonEnumHelper<>(MergeRequestScope.class);
@JsonCreator
public static MergeRequestScope 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 querying the state of a MergeRequest */ /** Enum to use for querying the state of a MergeRequest */
public enum MergeRequestState { public enum MergeRequestState {
......
...@@ -23,7 +23,7 @@ public class GitLabApiForm extends Form { ...@@ -23,7 +23,7 @@ public class GitLabApiForm extends Form {
* @param value the value of the field/attribute to add * @param value the value of the field/attribute to add
* @return this GitLabAPiForm instance * @return this GitLabAPiForm instance
*/ */
protected GitLabApiForm withParam(String name, Object value) throws IllegalArgumentException { public GitLabApiForm withParam(String name, Object value) throws IllegalArgumentException {
return (withParam(name, value, false)); return (withParam(name, value, false));
} }
...@@ -37,7 +37,7 @@ public class GitLabApiForm extends Form { ...@@ -37,7 +37,7 @@ public class GitLabApiForm extends Form {
* @return this GitLabAPiForm instance * @return this GitLabAPiForm instance
* @throws IllegalArgumentException if a required parameter is null or empty * @throws IllegalArgumentException if a required parameter is null or empty
*/ */
protected GitLabApiForm withParam(String name, Object value, boolean required) throws IllegalArgumentException { public GitLabApiForm withParam(String name, Object value, boolean required) throws IllegalArgumentException {
if (value == null) { if (value == null) {
......
...@@ -5,11 +5,13 @@ import java.util.Optional; ...@@ -5,11 +5,13 @@ import java.util.Optional;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.MergeRequestFilter;
import org.gitlab4j.api.models.Participant; import org.gitlab4j.api.models.Participant;
/** /**
...@@ -21,6 +23,52 @@ public class MergeRequestApi extends AbstractApi { ...@@ -21,6 +23,52 @@ public class MergeRequestApi extends AbstractApi {
super(gitLabApi); super(gitLabApi);
} }
/**
* Get all merge requests matching the filter.
*
* GET /merge_requests
*
* @param filter a MergeRequestFilter instance with the filter settings
* @return all merge requests for the specified project matching the filter
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(MergeRequestFilter filter) throws GitLabApiException {
return (getMergeRequests(filter, 1, getDefaultPerPage()));
}
/**
* Get all merge requests matching the filter.
*
* GET /merge_requests
*
* @param filter a MergeRequestFilter instance with the filter settings
* @param page the page to get
* @param perPage the number of MergeRequest instances per page
* @return all merge requests for the specified project matching the filter
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(MergeRequestFilter filter, int page, int perPage) throws GitLabApiException {
MultivaluedMap<String, String> queryParams = (filter != null ?
filter.getQueryParams(page, perPage).asMap() : getPageQueryParams(page, perPage));
Response response = get(Response.Status.OK, queryParams, "merge_requests");
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
}
/**
* Get all merge requests matching the filter.
*
* GET /merge_requests
*
* @param filter a MergeRequestFilter instance with the filter settings
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
* @return all merge requests for the specified project matching the filter
* @throws GitLabApiException if any exception occurs
*/
public Pager<MergeRequest> getMergeRequests(MergeRequestFilter filter, int itemsPerPage) throws GitLabApiException {
MultivaluedMap<String, String> queryParams = (filter != null ? filter.getQueryParams().asMap() : null);
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, queryParams, "merge_requests"));
}
/** /**
* Get all merge requests for the specified project. * Get all merge requests for the specified project.
* *
......
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