diff --git a/src/main/java/org/gitlab4j/api/Constants.java b/src/main/java/org/gitlab4j/api/Constants.java index 3ebc156097d049f1dd82f5e7a48e18d56c80f443..5e15bf4f83989e776b43a82649e447bd652b9374 100644 --- a/src/main/java/org/gitlab4j/api/Constants.java +++ b/src/main/java/org/gitlab4j/api/Constants.java @@ -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 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(). */ public enum GroupOrderBy { @@ -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 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 */ public enum MergeRequestState { diff --git a/src/main/java/org/gitlab4j/api/GitLabApiForm.java b/src/main/java/org/gitlab4j/api/GitLabApiForm.java index e15bc7f611c58e360e29dde5a6f35ab348a1755e..8abf540caa0a3ff7a8c900ee2391d6dda895a1f2 100644 --- a/src/main/java/org/gitlab4j/api/GitLabApiForm.java +++ b/src/main/java/org/gitlab4j/api/GitLabApiForm.java @@ -23,7 +23,7 @@ public class GitLabApiForm extends Form { * @param value the value of the field/attribute to add * @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)); } @@ -37,7 +37,7 @@ public class GitLabApiForm extends Form { * @return this GitLabAPiForm instance * @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) { diff --git a/src/main/java/org/gitlab4j/api/MergeRequestApi.java b/src/main/java/org/gitlab4j/api/MergeRequestApi.java index fdf62cfbac0c559076e2c1504236f0fab80a1b68..67b386ff84c744972686f3274a77f37d503853c1 100644 --- a/src/main/java/org/gitlab4j/api/MergeRequestApi.java +++ b/src/main/java/org/gitlab4j/api/MergeRequestApi.java @@ -5,11 +5,13 @@ import java.util.Optional; import javax.ws.rs.core.Form; import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.MultivaluedMap; 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.models.MergeRequestFilter; import org.gitlab4j.api.models.Participant; /** @@ -21,6 +23,52 @@ public class MergeRequestApi extends AbstractApi { 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 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 getMergeRequests(MergeRequestFilter filter, int page, int perPage) throws GitLabApiException { + MultivaluedMap 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>() {})); + } + + /** + * 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 getMergeRequests(MergeRequestFilter filter, int itemsPerPage) throws GitLabApiException { + MultivaluedMap queryParams = (filter != null ? filter.getQueryParams().asMap() : null); + return (new Pager(this, MergeRequest.class, itemsPerPage, queryParams, "merge_requests")); + } + /** * Get all merge requests for the specified project. *