Skip to content

Commit d8f9b2f

Browse files
committed
Added getOptionalMergeRequest().
1 parent a5c8620 commit d8f9b2f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.gitlab4j.api;
22

33
import java.util.List;
4+
import java.util.Optional;
45

56
import javax.ws.rs.core.Form;
67
import javax.ws.rs.core.GenericType;
@@ -131,6 +132,25 @@ public MergeRequest getMergeRequest(Integer projectId, Integer mergeRequestIid)
131132
return (response.readEntity(MergeRequest.class));
132133
}
133134

135+
/**
136+
* Get information about a single merge request as an Optional instance.
137+
*
138+
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
139+
*
140+
* GET /projects/:id/merge_requests/:merge_request_id
141+
*
142+
* @param projectId the project ID of the merge request
143+
* @param mergeRequestIid the internal ID of the merge request
144+
* @return the specified MergeRequest as an Optional instance instance
145+
*/
146+
public Optional<MergeRequest> getOptionalMergeRequest(Integer projectId, Integer mergeRequestIid) {
147+
try {
148+
return (Optional.ofNullable(getMergeRequest(projectId, mergeRequestIid)));
149+
} catch (GitLabApiException glae) {
150+
return (GitLabApi.createOptionalFromException(glae));
151+
}
152+
}
153+
134154
/**
135155
* Get a list of merge request commits.
136156
*

0 commit comments

Comments
 (0)