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
ebc2eb04
Commit
ebc2eb04
authored
Jan 28, 2018
by
Greg Messner
Browse files
Added Optional<> support (#127).
parent
bcd278bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/IssuesApi.java
View file @
ebc2eb04
...
...
@@ -25,6 +25,7 @@ package org.gitlab4j.api;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.Response
;
...
...
@@ -147,6 +148,23 @@ public class IssuesApi extends AbstractApi implements Constants {
return
(
response
.
readEntity
(
Issue
.
class
));
}
/**
* Get a single project issue as an Optional instance.
*
* GET /projects/:id/issues/:issue_iid
*
* @param projectId the project ID to get the issue for
* @param issueId the internal ID of a project's issue
* @return the specified Issue as an Optional instance
*/
public
Optional
<
Issue
>
getOptionalIssue
(
Integer
projectId
,
Integer
issueId
)
{
try
{
return
(
Optional
.
ofNullable
(
getIssue
(
projectId
,
issueId
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
}
/**
* Create an issue for the project.
*
...
...
@@ -462,13 +480,13 @@ public class IssuesApi extends AbstractApi implements Constants {
}
/**
* Get time tracking stats
* Get time tracking stats
.
*
* GET /projects/:id/issues/:issue_iid/time_stats
*
* @param projectId the project ID that owns the issue
* @param issueIid the internal ID of a project's issue
* @return a TimeS
T
ats instance
* @return a TimeS
t
ats instance
* @throws GitLabApiException if any exception occurs
*/
public
TimeStats
getTimeTrackingStats
(
Integer
projectId
,
Integer
issueIid
)
throws
GitLabApiException
{
...
...
@@ -484,4 +502,21 @@ public class IssuesApi extends AbstractApi implements Constants {
Response
response
=
get
(
Response
.
Status
.
OK
,
new
GitLabApiForm
().
asMap
(),
"projects"
,
projectId
,
"issues"
,
issueIid
,
"time_stats"
);
return
(
response
.
readEntity
(
TimeStats
.
class
));
}
/**
* Get time tracking stats as an Optional instance
*
* GET /projects/:id/issues/:issue_iid/time_stats
*
* @param projectId the project ID that owns the issue
* @param issueIid the internal ID of a project's issue
* @return a TimeStats as an Optional instance
*/
public
Optional
<
TimeStats
>
getOptionalTimeTrackingStats
(
Integer
projectId
,
Integer
issueIid
)
{
try
{
return
(
Optional
.
ofNullable
(
getTimeTrackingStats
(
projectId
,
issueIid
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
}
}
src/main/java/org/gitlab4j/api/JobApi.java
View file @
ebc2eb04
...
...
@@ -6,6 +6,7 @@ import java.io.InputStream;
import
java.nio.file.Files
;
import
java.nio.file.StandardCopyOption
;
import
java.util.List
;
import
java.util.Optional
;
import
javax.ws.rs.core.Form
;
import
javax.ws.rs.core.GenericType
;
...
...
@@ -134,6 +135,23 @@ public class JobApi extends AbstractApi implements Constants {
return
(
response
.
readEntity
(
Job
.
class
));
}
/**
* Get single job in a project as an Optional instance.
*
* GET /projects/:id/jobs/:job_id
*
* @param projectId the project ID to get the specified job for
* @param jobId the job ID to get
* @return a single job for the specified project ID as an Optional intance
*/
public
Optional
<
Job
>
getOptionalJob
(
int
projectId
,
int
jobId
)
{
try
{
return
(
Optional
.
ofNullable
(
getJob
(
projectId
,
jobId
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
}
/**
* Download the artifacts file from the given reference name and job provided the job finished successfully.
* The file will be saved to the specified directory. If the file already exists in the directory it will
...
...
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