Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
bcd278bb
Commit
bcd278bb
authored
Jan 28, 2018
by
Greg Messner
Browse files
Added Optional<> support (#127).
parent
02f1b7ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/CommitsApi.java
View file @
bcd278bb
...
...
@@ -4,6 +4,7 @@ import java.io.UnsupportedEncodingException;
import
java.net.URLEncoder
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
javax.ws.rs.core.Form
;
import
javax.ws.rs.core.GenericType
;
...
...
@@ -194,6 +195,23 @@ public class CommitsApi extends AbstractApi {
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.
*
...
...
src/main/java/org/gitlab4j/api/DeployKeysApi.java
View file @
bcd278bb
package
org.gitlab4j.api
;
import
java.util.List
;
import
java.util.Optional
;
import
javax.ws.rs.core.Form
;
import
javax.ws.rs.core.GenericType
;
...
...
@@ -138,6 +139,23 @@ public class DeployKeysApi extends AbstractApi {
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.
*
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment