Skip to content

Commit

Permalink
Consolidated method calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmessner committed Dec 17, 2017
1 parent 067a73d commit e0eb2cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/gitlab4j/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ public String toString() {

/** 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));
Expand All @@ -190,7 +190,6 @@ public String toString() {
}
}


/** Enum to use for specifying the state of a merge request or issue update. */
public enum StateEvent {

Expand Down
44 changes: 19 additions & 25 deletions src/main/java/org/gitlab4j/api/MergeRequestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public MergeRequestApi(GitLabApi gitLabApi) {
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "merge_requests");
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
return (getMergeRequests(projectId, 1, getDefaultPerPage()));
}

/**
Expand Down Expand Up @@ -64,60 +63,55 @@ public Pager<MergeRequest> getMergeRequests(Integer projectId, int itemsPerPage)
}

/**
* Get all merge requests for the specified project.
* Get all merge requests with a specific state for the specified project.
*
* GET /projects/:id/merge_requests
* GET /projects/:id/merge_requests?state=:state
*
* @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>>() {}));
public List<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state) throws GitLabApiException {
return (getMergeRequests(projectId, state, 1, getDefaultPerPage()));
}


/**
* 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).
* @param page the page to get
* @param perPage the number of MergeRequest instances per page
* @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 {
public List<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state, int page, int perPage) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("state", state);
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(), "projects", projectId, "merge_requests"));
.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 with a specific state for the specified project.
* Get all merge requests for the specified project.
*
* GET /projects/:id/merge_requests?state=:state
* GET /projects/:id/merge_requests
*
* @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).
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
* @return all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state) throws GitLabApiException {
public Pager<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state, int itemsPerPage) 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>>() {}));
.withParam("state", state);
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(), "projects", projectId, "merge_requests"));
}

/**
Expand Down

0 comments on commit e0eb2cc

Please sign in to comment.