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
25b05ef9
Commit
25b05ef9
authored
Sep 16, 2019
by
Greg Messner
Browse files
Mods to add getPipelineVariables() support (#431).
parent
f0cf47f6
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/PipelineApi.java
View file @
25b05ef9
...
@@ -752,4 +752,48 @@ public class PipelineApi extends AbstractApi implements Constants {
...
@@ -752,4 +752,48 @@ public class PipelineApi extends AbstractApi implements Constants {
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"trigger"
,
"pipeline"
);
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"trigger"
,
"pipeline"
);
return
(
response
.
readEntity
(
Pipeline
.
class
));
return
(
response
.
readEntity
(
Pipeline
.
class
));
}
}
/**
* Get List of variables of a pipeline.
*
* <pre><code>GET /projects/:id/pipelines/:pipeline_id/variables</code></pre>
*
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
* @param pipelineId the pipeline ID
* @return a List of pipeline variables
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Variable
>
getPipelineVariables
(
Object
projectIdOrPath
,
Integer
pipelineId
)
throws
GitLabApiException
{
return
(
getPipelineVariables
(
projectIdOrPath
,
pipelineId
,
getDefaultPerPage
()).
all
());
}
/**
* Get a Pager of variables of a pipeline.
*
* <pre><code>GET /projects/:id/pipelines/:pipeline_id/variables</code></pre>
*
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
* @param pipelineId the pipeline ID
* @param itemsPerPage the number of Pipeline instances that will be fetched per page
* @return a Pager of pipeline variables
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
Variable
>
getPipelineVariables
(
Object
projectIdOrPath
,
Integer
pipelineId
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
new
Pager
<
Variable
>(
this
,
Variable
.
class
,
itemsPerPage
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"pipelines"
,
pipelineId
,
"variables"
));
}
/**
* Get a Stream of variables of a pipeline as a Stream.
*
* <pre><code>GET /projects/:id/pipelines/:pipeline_id/variables</code></pre>
*
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
* @param pipelineId the pipeline ID
* @return a Stream of pipeline variables
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
Variable
>
getPipelineVariablesStream
(
Object
projectIdOrPath
,
Integer
pipelineId
)
throws
GitLabApiException
{
return
(
getPipelineVariables
(
projectIdOrPath
,
pipelineId
,
getDefaultPerPage
()).
stream
());
}
}
}
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
25b05ef9
...
@@ -312,6 +312,12 @@ public class TestGitLabApiBeans {
...
@@ -312,6 +312,12 @@ public class TestGitLabApiBeans {
assertTrue
(
compareJson
(
pipelineSchedule
,
"pipeline-schedule.json"
));
assertTrue
(
compareJson
(
pipelineSchedule
,
"pipeline-schedule.json"
));
}
}
@Test
public
void
testPipelineVariables
()
throws
Exception
{
List
<
Variable
>
variables
=
unmarshalResourceList
(
Variable
.
class
,
"pipeline-variables.json"
);
assertTrue
(
compareJson
(
variables
,
"pipeline-variables.json"
));
}
@Test
@Test
public
void
testProjectVariables
()
throws
Exception
{
public
void
testProjectVariables
()
throws
Exception
{
List
<
Variable
>
variables
=
unmarshalResourceList
(
Variable
.
class
,
"project-variables.json"
);
List
<
Variable
>
variables
=
unmarshalResourceList
(
Variable
.
class
,
"project-variables.json"
);
...
...
src/test/java/org/gitlab4j/api/TestPipelineApi.java
View file @
25b05ef9
package
org.gitlab4j.api
;
package
org.gitlab4j.api
;
import
static
java
.
util
.
stream
.
Collectors
.
toList
;
import
static
java
.
util
.
stream
.
Collectors
.
toList
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
@@ -290,4 +291,41 @@ public class TestPipelineApi extends AbstractIntegrationTest {
...
@@ -290,4 +291,41 @@ public class TestPipelineApi extends AbstractIntegrationTest {
gitLabApi
.
getPipelineApi
().
deletePipeline
(
testProject
,
pipeline
.
getId
());
gitLabApi
.
getPipelineApi
().
deletePipeline
(
testProject
,
pipeline
.
getId
());
}
}
@Test
public
void
testPipelineVariables
()
throws
GitLabApiException
{
// Skip this test if no .gitlab-ci.yml file is in the test project
assumeNotNull
(
gitlabCiYml
);
// Arrange
Map
<
String
,
String
>
variableMap
=
new
HashMap
<>();
variableMap
.
put
(
"VAR1"
,
"value1"
);
variableMap
.
put
(
"VAR2"
,
"value2"
);
// Act
Pipeline
pipeline
=
gitLabApi
.
getPipelineApi
().
createPipeline
(
testProject
,
"master"
,
variableMap
);
// Assert
assertNotNull
(
pipeline
);
try
{
Stream
<
Variable
>
stream
=
gitLabApi
.
getPipelineApi
().
getPipelineVariablesStream
(
testProject
,
pipeline
.
getId
());
stream
.
forEach
(
v
->
{
String
value
=
variableMap
.
get
(
v
.
getKey
());
assertEquals
(
value
,
v
.
getValue
());
});
List
<
Variable
>
variables
=
gitLabApi
.
getPipelineApi
().
getPipelineVariables
(
testProject
,
pipeline
.
getId
());
assertEquals
(
variableMap
.
size
(),
variables
.
size
());
variables
.
forEach
(
v
->
{
String
value
=
variableMap
.
get
(
v
.
getKey
());
assertEquals
(
value
,
v
.
getValue
());
});
}
finally
{
gitLabApi
.
getPipelineApi
().
deletePipeline
(
testProject
,
pipeline
.
getId
());
}
}
}
}
src/test/resources/org/gitlab4j/api/pipeline-variables.json
0 → 100644
View file @
25b05ef9
[
{
"key"
:
"RUN_NIGHTLY_BUILD"
,
"variable_type"
:
"env_var"
,
"value"
:
"true"
},
{
"key"
:
"foo"
,
"value"
:
"bar"
}
]
\ No newline at end of file
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