Skip to content

Commit e0eb2cc

Browse files
committed
Consolidated method calls.
1 parent 067a73d commit e0eb2cc

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

src/main/java/org/gitlab4j/api/Constants.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ public String toString() {
171171

172172
/** Enum to use for querying the state of a MergeRequest */
173173
public enum MergeRequestState {
174+
174175
OPENED, CLOSED, MERGED, ALL;
175176

176177
private static JacksonJsonEnumHelper<MergeRequestState> enumHelper = new JacksonJsonEnumHelper<>(MergeRequestState.class);
177178

178179
@JsonCreator
179180
public static MergeRequestState forValue(String value) { return enumHelper.forValue(value); }
180181

181-
182182
@JsonValue
183183
public String toValue() {
184184
return (enumHelper.toString(this));
@@ -190,7 +190,6 @@ public String toString() {
190190
}
191191
}
192192

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

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

+19-25
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public MergeRequestApi(GitLabApi gitLabApi) {
2929
* @throws GitLabApiException if any exception occurs
3030
*/
3131
public List<MergeRequest> getMergeRequests(Integer projectId) throws GitLabApiException {
32-
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "merge_requests");
33-
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
32+
return (getMergeRequests(projectId, 1, getDefaultPerPage()));
3433
}
3534

3635
/**
@@ -64,60 +63,55 @@ public Pager<MergeRequest> getMergeRequests(Integer projectId, int itemsPerPage)
6463
}
6564

6665
/**
67-
* Get all merge requests for the specified project.
66+
* Get all merge requests with a specific state for the specified project.
6867
*
69-
* GET /projects/:id/merge_requests
68+
* GET /projects/:id/merge_requests?state=:state
7069
*
7170
* @param projectId the project ID to get the merge requests for
72-
* @param page the page to get
73-
* @param perPage the number of MergeRequest instances per page
7471
* @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).
7572
* @return all merge requests for the specified project
7673
* @throws GitLabApiException if any exception occurs
7774
*/
78-
public List<MergeRequest> getMergeRequests(Integer projectId, int page, int perPage, MergeRequestState state) throws GitLabApiException {
79-
Form formData = new GitLabApiForm()
80-
.withParam("state", state)
81-
.withParam(PAGE_PARAM, page)
82-
.withParam(PER_PAGE_PARAM, perPage);
83-
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests");
84-
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
75+
public List<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state) throws GitLabApiException {
76+
return (getMergeRequests(projectId, state, 1, getDefaultPerPage()));
8577
}
8678

87-
8879
/**
8980
* Get all merge requests for the specified project.
9081
*
9182
* GET /projects/:id/merge_requests
9283
*
9384
* @param projectId the project ID to get the merge requests for
94-
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
9585
* @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).
86+
* @param page the page to get
87+
* @param perPage the number of MergeRequest instances per page
9688
* @return all merge requests for the specified project
9789
* @throws GitLabApiException if any exception occurs
9890
*/
99-
public Pager<MergeRequest> getMergeRequests(Integer projectId, int itemsPerPage, MergeRequestState state) throws GitLabApiException {
91+
public List<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state, int page, int perPage) throws GitLabApiException {
10092
Form formData = new GitLabApiForm()
101-
.withParam("state", state);
102-
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(), "projects", projectId, "merge_requests"));
93+
.withParam("state", state)
94+
.withParam(PAGE_PARAM, page)
95+
.withParam(PER_PAGE_PARAM, perPage);
96+
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests");
97+
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
10398
}
10499

105100
/**
106-
* Get all merge requests with a specific state for the specified project.
101+
* Get all merge requests for the specified project.
107102
*
108-
* GET /projects/:id/merge_requests?state=:state
103+
* GET /projects/:id/merge_requests
109104
*
110105
* @param projectId the project ID to get the merge requests for
111106
* @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).
107+
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
112108
* @return all merge requests for the specified project
113109
* @throws GitLabApiException if any exception occurs
114110
*/
115-
public List<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state) throws GitLabApiException {
111+
public Pager<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state, int itemsPerPage) throws GitLabApiException {
116112
Form formData = new GitLabApiForm()
117-
.withParam("state", state)
118-
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
119-
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests");
120-
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
113+
.withParam("state", state);
114+
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(), "projects", projectId, "merge_requests"));
121115
}
122116

123117
/**

0 commit comments

Comments
 (0)