Skip to content

Commit c292eb7

Browse files
jeroenwijdemansgmessner
authored andcommitted
Added support to list MergeRequests by state (#110)
* Added support to list MergeRequests by state * Added getMergeRequests by State with paging support
1 parent 9fe4c51 commit c292eb7

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,28 @@ public String toString() {
169169
}
170170
}
171171

172+
/** Enum to use for querying the state of a MergeRequest */
173+
public enum MergeRequestState {
174+
OPENED, CLOSED, MERGED, ALL;
175+
176+
private static JacksonJsonEnumHelper<MergeRequestState> enumHelper = new JacksonJsonEnumHelper<>(MergeRequestState.class);
177+
178+
@JsonCreator
179+
public static MergeRequestState forValue(String value) { return enumHelper.forValue(value); }
180+
181+
182+
@JsonValue
183+
public String toValue() {
184+
return (enumHelper.toString(this));
185+
}
186+
187+
@Override
188+
public String toString() {
189+
return (enumHelper.toString(this));
190+
}
191+
}
192+
193+
172194
/** Enum to use for specifying the state of a merge request or issue update. */
173195
public enum StateEvent {
174196

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,63 @@ public Pager<MergeRequest> getMergeRequests(Integer projectId, int itemsPerPage)
6363
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, null, "projects", projectId, "merge_requests"));
6464
}
6565

66+
/**
67+
* Get all merge requests for the specified project.
68+
*
69+
* GET /projects/:id/merge_requests
70+
*
71+
* @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
74+
* @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).
75+
* @return all merge requests for the specified project
76+
* @throws GitLabApiException if any exception occurs
77+
*/
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>>() {}));
85+
}
86+
87+
88+
/**
89+
* Get all merge requests for the specified project.
90+
*
91+
* GET /projects/:id/merge_requests
92+
*
93+
* @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
95+
* @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).
96+
* @return all merge requests for the specified project
97+
* @throws GitLabApiException if any exception occurs
98+
*/
99+
public Pager<MergeRequest> getMergeRequests(Integer projectId, int itemsPerPage, MergeRequestState state) throws GitLabApiException {
100+
Form formData = new GitLabApiForm()
101+
.withParam("state", state);
102+
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(), "projects", projectId, "merge_requests"));
103+
}
104+
105+
/**
106+
* Get all merge requests with a specific state for the specified project.
107+
*
108+
* GET /projects/:id/merge_requests?state=:state
109+
*
110+
* @param projectId the project ID to get the merge requests for
111+
* @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).
112+
* @return all merge requests for the specified project
113+
* @throws GitLabApiException if any exception occurs
114+
*/
115+
public List<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state) throws GitLabApiException {
116+
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>>() {}));
121+
}
122+
66123
/**
67124
* Get information about a single merge request.
68125
*

0 commit comments

Comments
 (0)