Commit bcd278bb authored by Greg Messner's avatar Greg Messner
Browse files

Added Optional<> support (#127).

parent 02f1b7ff
...@@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException; ...@@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
...@@ -194,6 +195,23 @@ public class CommitsApi extends AbstractApi { ...@@ -194,6 +195,23 @@ public class CommitsApi extends AbstractApi {
return (response.readEntity(Commit.class)); return (response.readEntity(Commit.class));
} }
/**
* Get a specific commit identified by the commit hash or name of a branch or tag as an Optional instance
*
* GET /projects/:id/repository/commits/:sha
*
* @param projectId the project ID that the commit belongs to
* @param sha a commit hash or name of a branch or tag
* @return the Commit for the specified project ID/sha pair as an Optional instance
*/
public Optional<Commit> getOptionalCommit(int projectId, String sha) {
try {
return (Optional.ofNullable(getCommit(projectId, sha)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/** /**
* Get the list of diffs of a commit in a project. * Get the list of diffs of a commit in a project.
* *
......
package org.gitlab4j.api; package org.gitlab4j.api;
import java.util.List; import java.util.List;
import java.util.Optional;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
...@@ -138,6 +139,23 @@ public class DeployKeysApi extends AbstractApi { ...@@ -138,6 +139,23 @@ public class DeployKeysApi extends AbstractApi {
return (response.readEntity(DeployKey.class)); return (response.readEntity(DeployKey.class));
} }
/**
* Get a single deploy key for the specified project as an Optional instance.
*
* GET /projects/:id/deploy_keys/:key_id
*
* @param projectId the ID of the project
* @param keyId the ID of the deploy key to delete
* @return the DeployKey for the specified project ID and key ID as an Optional instance
*/
public Optional<DeployKey> getOptionalDeployKey(Integer projectId, Integer keyId) {
try {
return (Optional.ofNullable(getDeployKey(projectId, keyId)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/** /**
* Creates a new deploy key for a project. * Creates a new deploy key for a project.
* *
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment