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
14ef9b76
Commit
14ef9b76
authored
Jul 11, 2017
by
Chen Chenglong
Committed by
Greg Messner
Jul 10, 2017
Browse files
Add Job API (#45)
parent
728c7383
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/Constants.java
View file @
14ef9b76
...
...
@@ -121,4 +121,21 @@ public interface Constants {
return
(
name
().
toLowerCase
());
}
}
/** Enum to use for specifying the scope when calling getJobs(). */
public
enum
JobScope
{
CREATED
,
PENDING
,
RUNNING
,
FAILED
,
SUCCESS
,
CANCELED
,
SKIPPED
,
MANUAL
;
private
static
JacksonJsonEnumHelper
<
JobScope
>
enumHelper
=
new
JacksonJsonEnumHelper
<>(
JobScope
.
class
);
@JsonCreator
public
static
JobScope
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
());
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
());
}
}
}
src/main/java/org/gitlab4j/api/GitLabApi.java
View file @
14ef9b76
...
...
@@ -37,6 +37,7 @@ public class GitLabApi {
private
ServicesApi
servicesApi
;
private
SessionApi
sessoinApi
;
private
UserApi
userApi
;
private
JobApi
jobApi
;
private
NotesApi
notesApi
;
private
Session
session
;
...
...
@@ -187,6 +188,7 @@ public class GitLabApi {
sessoinApi
=
new
SessionApi
(
this
);
userApi
=
new
UserApi
(
this
);
repositoryFileApi
=
new
RepositoryFileApi
(
this
);
jobApi
=
new
JobApi
(
this
);
notesApi
=
new
NotesApi
(
this
);
}
...
...
@@ -238,10 +240,10 @@ public class GitLabApi {
GitLabApiClient
getApiClient
()
{
return
(
apiClient
);
}
/**
* Get the version info for the GitLab server using the GitLab Version API.
*
*
* @return the version info for the GitLab server
* @throws GitLabApiException if any exception occurs
*/
...
...
@@ -371,6 +373,14 @@ public class GitLabApi {
return
(
userApi
);
}
/**
* Gets the JobApi instance owned by this GitLabApi instance. The JobApi is used
* to perform all jobs related API calls.
*
* @return the JobsApi instance owned by this GitLabApi instance
*/
public
JobApi
getJobApi
()
{
return
(
jobApi
);
}
/**
* Gets the NotesApi instance owned by this GitLabApi instance. The NotesApi is used
* to perform all notes related API calls.
...
...
@@ -380,4 +390,5 @@ public class GitLabApi {
public
NotesApi
getNotesApi
()
{
return
(
notesApi
);
}
}
src/main/java/org/gitlab4j/api/JobApi.java
0 → 100644
View file @
14ef9b76
package
org.gitlab4j.api
;
import
org.gitlab4j.api.models.Job
;
import
java.util.List
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response.Status
;
/**
* This class provides an entry point to all the GitLab API job calls.
*/
public
class
JobApi
extends
AbstractApi
implements
Constants
{
public
JobApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
/**
* Get a list of jobs in a project.
*
* GET /projects/:id/jobs
*
* @param projectId the project ID to get the list of jobs for
* @return a list containing the jobs for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public
List
<
Job
>
getJobsFromProjectId
(
int
projectId
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getDefaultPerPageParam
(),
"projects"
,
projectId
,
"jobs"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Job
>>()
{
}));
}
/**
* Get a list of jobs in a project in the specified page range.
*
* GET /projects/:id/jobs
*
* @param projectId the project ID to get the list of jobs for
* @param page the page to get
* @param perPage the number of Job instances per page
* @return a list containing the jobs for the specified project ID in the specified page range
* @throws GitLabApiException if any exception occurs during execution
*/
public
List
<
Job
>
getJobsFromProjectId
(
int
projectId
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getPageQueryParams
(
page
,
perPage
),
"projects"
,
projectId
,
"jobs"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Job
>>()
{
}));
}
/**
* Get a Pager of jobs in a project.
*
* GET /projects/:id/jobs
*
* @param projectId the project ID to get the list of jobs for
* @param itemsPerPage the number of Job instances that will be fetched per page
* @return a Pager containing the jobs for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public
Pager
<
Job
>
getJobsFromProjectId
(
int
projectId
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
new
Pager
<
Job
>(
this
,
Job
.
class
,
itemsPerPage
,
null
,
"projects"
,
projectId
,
"jobs"
));
}
/**
* Get a list of jobs in a project.
*
* GET /projects/:id/jobs
*
* @param projectId the project ID to get the list of jobs for
* @param scope the scope of jobs, one of: CREATED, PENDING, RUNNING, FAILED, SUCCESS, CANCELED, SKIPPED, MANUAL
* @return a list containing the jobs for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public
List
<
Job
>
getJobsFromProjectId
(
int
projectId
,
JobScope
scope
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"scope"
,
scope
)
.
withParam
(
PER_PAGE_PARAM
,
getDefaultPerPage
());
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"jobs"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Job
>>()
{
}));
}
/**
* Get a list of jobs in a pipeline.
*
* GET /projects/:id/pipelines/:pipeline_id/jobs
*
* @param projectId the project ID to get the list of pipeline for
* @param pipelineId the pipeline ID to get the list of jobs for
* @return a list containing the jobs for the specified project ID and pipeline ID
* @throws GitLabApiException if any exception occurs during execution
*/
public
List
<
Job
>
getJobsFromPipelineId
(
int
projectId
,
int
pipelineId
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getDefaultPerPageParam
(),
"projects"
,
projectId
,
"pipelines"
,
pipelineId
,
"jobs"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Job
>>()
{
}));
}
/**
* Get a list of jobs in a pipeline.
*
* GET /projects/:id/pipelines/:pipeline_id/jobs
*
* @param projectId the project ID to get the list of pipeline for
* @param pipelineId the pipeline ID to get the list of jobs for
* @param scope the scope of jobs, one of: CREATED, PENDING, RUNNING, FAILED, SUCCESS, CANCELED, SKIPPED, MANUAL
* @return a list containing the jobs for the specified project ID and pipeline ID
* @throws GitLabApiException if any exception occurs during execution
*/
public
List
<
Job
>
getJobsFromPipelineId
(
int
projectId
,
int
pipelineId
,
JobScope
scope
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"scope"
,
scope
)
.
withParam
(
PER_PAGE_PARAM
,
getDefaultPerPage
());
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"pipelines"
,
pipelineId
,
"jobs"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Job
>>()
{
}));
}
/**
* Get single job in a project.
*
* 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
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
getJob
(
int
projectId
,
int
jobId
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
projectId
,
"jobs"
,
jobId
);
return
(
response
.
readEntity
(
Job
.
class
));
}
/**
* Cancel specified job in a project.
*
* POST /projects/:id/jobs/:job_id/cancel
*
* @param projectId the project ID to cancel speficied job
* @param jobId the ID to cancel job
* @return job instance which just canceled
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
cancleJob
(
int
projectId
,
int
jobId
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
null
;
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"projects"
,
projectId
,
"jobs"
,
jobId
,
"cancel"
);
return
(
response
.
readEntity
(
Job
.
class
));
}
/**
* Retry specified job in a project.
*
* POST /projects/:id/jobs/:job_id/retry
*
* @param projectId the project ID to retry speficied job
* @param jobId the ID to retry job
* @return job instance which just retried
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
retryJob
(
int
projectId
,
int
jobId
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
null
;
Response
response
=
post
(
Status
.
CREATED
,
formData
,
"projects"
,
projectId
,
"jobs"
,
jobId
,
"retry"
);
return
(
response
.
readEntity
(
Job
.
class
));
}
/**
* Erase specified job in a project.
*
* POST /projects/:id/jobs/:job_id/erase
*
* @param projectId the project ID to erase speficied job
* @param jobId the ID to erase job
* @return job instance which just erased
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
eraseJob
(
int
projectId
,
int
jobId
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
null
;
Response
response
=
post
(
Status
.
CREATED
,
formData
,
"projects"
,
projectId
,
"jobs"
,
jobId
,
"erase"
);
return
(
response
.
readEntity
(
Job
.
class
));
}
/**
* Play specified job in a project.
*
* POST /projects/:id/jobs/:job_id/play
*
* @param projectId the project ID to play speficied job
* @param jobId the ID to play job
* @return job instance which just played
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
playJob
(
int
projectId
,
int
jobId
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
null
;
Response
response
=
post
(
Status
.
CREATED
,
formData
,
"projects"
,
projectId
,
"jobs"
,
jobId
,
"play"
);
return
(
response
.
readEntity
(
Job
.
class
));
}
}
src/main/java/org/gitlab4j/api/models/ArtifactsFile.java
0 → 100644
View file @
14ef9b76
package
org.gitlab4j.api.models
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
ArtifactsFile
{
private
String
filename
;
private
Integer
size
;
public
String
getFilename
()
{
return
filename
;
}
public
void
setFilename
(
String
filename
)
{
this
.
filename
=
filename
;
}
public
Integer
getSize
()
{
return
size
;
}
public
void
setSize
(
Integer
size
)
{
this
.
size
=
size
;
}
}
src/main/java/org/gitlab4j/api/models/Job.java
0 → 100644
View file @
14ef9b76
package
org.gitlab4j.api.models
;
import
java.util.Date
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Job
{
private
Integer
id
;
private
Commit
commit
;
private
String
coverage
;
private
Date
created_at
;
private
Date
finished_at
;
private
String
name
;
private
Pipeline
pipeline
;
private
String
ref
;
private
Runner
runner
;
private
User
user
;
private
Date
started_at
;
private
ArtifactsFile
artifacts_file
;
private
Boolean
tag
;
private
String
stage
;
private
JobStatus
status
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Commit
getCommit
()
{
return
commit
;
}
public
void
setCommit
(
Commit
commit
)
{
this
.
commit
=
commit
;
}
public
Date
getCreated_at
()
{
return
created_at
;
}
public
void
setCreated_at
(
Date
created_at
)
{
this
.
created_at
=
created_at
;
}
public
Date
getFinished_at
()
{
return
finished_at
;
}
public
void
setFinished_at
(
Date
finished_at
)
{
this
.
finished_at
=
finished_at
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
Pipeline
getPipeline
()
{
return
pipeline
;
}
public
void
setPipeline
(
Pipeline
pipeline
)
{
this
.
pipeline
=
pipeline
;
}
public
String
getRef
()
{
return
ref
;
}
public
void
setRef
(
String
ref
)
{
this
.
ref
=
ref
;
}
public
User
getUser
()
{
return
user
;
}
public
void
setUser
(
User
user
)
{
this
.
user
=
user
;
}
public
Date
getStarted_at
()
{
return
started_at
;
}
public
void
setStarted_at
(
Date
started_at
)
{
this
.
started_at
=
started_at
;
}
public
Boolean
getTag
()
{
return
tag
;
}
public
void
setTag
(
Boolean
tag
)
{
this
.
tag
=
tag
;
}
public
String
getStage
()
{
return
stage
;
}
public
void
setStage
(
String
stage
)
{
this
.
stage
=
stage
;
}
public
JobStatus
getStatus
()
{
return
status
;
}
public
void
setStatus
(
JobStatus
status
)
{
this
.
status
=
status
;
}
public
String
getCoverage
()
{
return
coverage
;
}
public
void
setCoverage
(
String
coverage
)
{
this
.
coverage
=
coverage
;
}
public
ArtifactsFile
getArtifacts_file
()
{
return
artifacts_file
;
}
public
void
setArtifacts_file
(
ArtifactsFile
artifacts_file
)
{
this
.
artifacts_file
=
artifacts_file
;
}
public
Runner
getRunner
()
{
return
runner
;
}
public
void
setRunner
(
Runner
runner
)
{
this
.
runner
=
runner
;
}
}
src/main/java/org/gitlab4j/api/models/JobStatus.java
0 → 100644
View file @
14ef9b76
package
org.gitlab4j.api.models
;
import
java.util.HashMap
;
import
java.util.Map
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonValue
;
/**
* Enum for the various Job status values.
*/
public
enum
JobStatus
{
RUNNING
,
PENDING
,
SUCCESS
,
FAILED
,
CANCELED
,
SKIPPED
;
private
static
Map
<
String
,
JobStatus
>
valuesMap
=
new
HashMap
<>(
6
);
static
{
for
(
JobStatus
status
:
JobStatus
.
values
())
valuesMap
.
put
(
status
.
toValue
(),
status
);
}
@JsonCreator
public
static
JobStatus
forValue
(
String
value
)
{
return
valuesMap
.
get
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
());
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
());
}
}
\ No newline at end of file
src/main/java/org/gitlab4j/api/models/Runner.java
0 → 100644
View file @
14ef9b76
package
org.gitlab4j.api.models
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
Runner
{
private
Integer
id
;
private
String
description
;
private
Boolean
active
;
private
Boolean
is_shared
;
private
String
name
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
Boolean
getActive
()
{
return
active
;
}
public
void
setActive
(
Boolean
active
)
{
this
.
active
=
active
;
}
public
Boolean
getIs_shared
()
{
return
is_shared
;
}
public
void
setIs_shared
(
Boolean
is_shared
)
{
this
.
is_shared
=
is_shared
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
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