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
0038a559
Commit
0038a559
authored
Jun 10, 2017
by
Greg Messner
Browse files
Modified to use enums instead of String literals.
parent
73d38d00
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/PipelineApi.java
View file @
0038a559
package
org.gitlab4j.api
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.models.Pipeline
;
import
org.gitlab4j.api.models.PipelineStatus
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonValue
;
/**
* This class provides an entry point to all the GitLab API pipeline calls.
*/
public
class
PipelineApi
extends
AbstractApi
{
/** Enum to use for specifying the scope when calling getPipelines(). */
public
enum
Scope
{
RUNNING
,
PENDING
,
FINISHED
,
BRANCHES
,
TAGS
;
private
static
Map
<
String
,
Scope
>
valuesMap
=
new
HashMap
<>(
5
);
static
{
for
(
Scope
scope
:
Scope
.
values
())
valuesMap
.
put
(
scope
.
toValue
(),
scope
);
}
@JsonCreator
public
static
Scope
forValue
(
String
value
)
{
return
valuesMap
.
get
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
());
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
());
}
}
/** Enum to use for ordering the results of getPipelines(). */
public
enum
OrderBy
{
ID
,
STATUS
,
REF
,
USER_ID
;
private
static
Map
<
String
,
OrderBy
>
valuesMap
=
new
HashMap
<>(
4
);
static
{
for
(
OrderBy
orderBy
:
OrderBy
.
values
())
valuesMap
.
put
(
orderBy
.
toValue
(),
orderBy
);
}
@JsonCreator
public
static
OrderBy
forValue
(
String
value
)
{
return
valuesMap
.
get
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
name
().
toLowerCase
());
}
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
());
}
}
public
PipelineApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
...
...
@@ -37,19 +97,19 @@ public class PipelineApi extends AbstractApi {
* GET /projects/:id/pipelines
*
* @param projectId the project ID to get the list of pipelines for
* @param scope the scope of pipelines, one of:
running, pending, finished, branches, tags
* @param status the status of pipelines, one of:
running, pending, success, failed, canceled, skipped
* @param scope the scope of pipelines, one of:
RUNNING, PENDING, FINISHED, BRANCHES, TAGS
* @param status the status of pipelines, one of:
RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
* @param ref the ref of pipelines
* @param yamlErrors returns pipelines with invalid configurations
* @param name the name of the user who triggered pipelines
* @param username the username of the user who triggered pipelines
* @param orderBy order pipelines by
id, status, ref, or user_id
(default:
id
)
* @param sort sort pipelines in
asc or desc
order (default:
desc
)
* @param orderBy order pipelines by
ID, STATUS, REF, USER_ID
(default:
ID
)
* @param sort sort pipelines in
"ASC" or "DESC"
order (default:
"DESC"
)
* @return a list containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public
List
<
Pipeline
>
getPipelines
(
int
projectId
,
S
tring
scope
,
String
status
,
String
ref
,
boolean
yamlErrors
,
String
name
,
String
username
,
String
orderBy
,
String
sort
)
throws
GitLabApiException
{
public
List
<
Pipeline
>
getPipelines
(
int
projectId
,
S
cope
scope
,
PipelineStatus
status
,
String
ref
,
boolean
yamlErrors
,
String
name
,
String
username
,
OrderBy
orderBy
,
String
sort
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"scope"
,
scope
)
.
withParam
(
"status"
,
status
)
...
...
@@ -58,7 +118,7 @@ public class PipelineApi extends AbstractApi {
.
withParam
(
"name"
,
name
)
.
withParam
(
"username"
,
username
)
.
withParam
(
"order_by"
,
orderBy
)
.
withParam
(
"sort"
,
sort
);
.
withParam
(
"sort"
,
(
sort
!=
null
?
sort
.
toLowerCase
()
:
null
)
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"pipelines"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Pipeline
>>()
{
...
...
src/main/java/org/gitlab4j/api/models/Pipeline.java
View file @
0038a559
...
...
@@ -11,7 +11,7 @@ import javax.xml.bind.annotation.XmlRootElement;
public
class
Pipeline
{
private
Integer
id
;
private
String
status
;
private
PipelineStatus
status
;
private
String
ref
;
private
String
sha
;
private
String
beforeSha
;
...
...
@@ -34,11 +34,11 @@ public class Pipeline {
this
.
id
=
id
;
}
public
String
getStatus
()
{
public
PipelineStatus
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
status
)
{
public
void
setStatus
(
PipelineStatus
status
)
{
this
.
status
=
status
;
}
...
...
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