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
485f341b
Commit
485f341b
authored
Jul 15, 2020
by
Greg Messner
Browse files
Added stopEnvironment()
parent
b47733e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/EnvironmentsApi.java
View file @
485f341b
...
...
@@ -129,6 +129,22 @@ public class EnvironmentsApi extends AbstractApi {
return
(
response
.
readEntity
(
Environment
.
class
));
}
/**
* Stop an environment.
*
* <pre><code>GitLab Endpoint: POST /projects/:id/environments/:environment_id/stop</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param environmentId the ID of the environment to stop
* @return the stopped Environment instance
* @throws GitLabApiException if any exception occurs
*/
public
Environment
stopEnvironment
(
Object
projectIdOrPath
,
Integer
environmentId
)
throws
GitLabApiException
{
Response
response
=
post
(
Response
.
Status
.
OK
,
(
GitLabApiForm
)
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"environments"
,
environmentId
,
"stop"
);
return
(
response
.
readEntity
(
Environment
.
class
));
}
/**
* Delete an environment.
*
...
...
src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java
View file @
485f341b
...
...
@@ -67,11 +67,14 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
for
(
Environment
env
:
envs
)
{
if
(
env
.
getName
().
startsWith
(
ENVIRONMENT_NAME
))
{
gitLabApi
.
getEnvironmentsApi
().
stopEnvironment
(
testProject
,
env
.
getId
());
gitLabApi
.
getEnvironmentsApi
().
deleteEnvironment
(
testProject
,
env
.
getId
());
}
}
}
}
catch
(
GitLabApiException
ignore
)
{
System
.
out
.
println
(
"ERROR"
);
}
}
}
...
...
@@ -91,23 +94,21 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
final
Environment
env
=
gitLabApi
.
getEnvironmentsApi
().
createEnvironment
(
testProject
,
getUniqueName
(),
EXTERNAL_URL
);
try
{
List
<
Environment
>
envs
=
gitLabApi
.
getEnvironmentsApi
().
getEnvironments
(
testProject
);
assertTrue
(
envs
.
size
()
>
0
);
Environment
foundEnv
=
envs
.
stream
().
filter
(
List
<
Environment
>
envs
=
gitLabApi
.
getEnvironmentsApi
().
getEnvironments
(
testProject
);
assertTrue
(
envs
.
size
()
>
0
);
Environment
foundEnv
=
envs
.
stream
().
filter
(
e
->
e
.
getName
().
equals
(
env
.
getName
())).
findFirst
().
orElse
(
null
);
assertNotNull
(
foundEnv
);
assertEquals
(
env
.
getName
(),
foundEnv
.
getName
());
}
catch
(
Exception
e
)
{
gitLabApi
.
getEnvironmentsApi
().
deleteEnvironment
(
testProject
,
env
.
getId
());
}
assertNotNull
(
foundEnv
);
assertEquals
(
env
.
getName
(),
foundEnv
.
getName
());
}
@Test
public
void
testDeleteEnvironment
()
throws
GitLabApiException
{
public
void
test
StopAnd
DeleteEnvironment
()
throws
GitLabApiException
{
final
Environment
env
=
gitLabApi
.
getEnvironmentsApi
().
createEnvironment
(
testProject
,
getUniqueName
(),
EXTERNAL_URL
);
gitLabApi
.
getEnvironmentsApi
().
stopEnvironment
(
testProject
,
env
.
getId
());
gitLabApi
.
getEnvironmentsApi
().
deleteEnvironment
(
testProject
,
env
.
getId
());
Stream
<
Environment
>
envs
=
gitLabApi
.
getEnvironmentsApi
().
getEnvironmentsStream
(
testProject
);
...
...
@@ -125,6 +126,7 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
assertTrue
(
optionalEnv
.
isPresent
());
assertEquals
(
env
.
getName
(),
optionalEnv
.
get
().
getName
());
gitLabApi
.
getEnvironmentsApi
().
stopEnvironment
(
testProject
,
env
.
getId
());
gitLabApi
.
getEnvironmentsApi
().
deleteEnvironment
(
testProject
,
env
.
getId
());
}
}
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