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
d8777afb
Commit
d8777afb
authored
Aug 07, 2024
by
Jeremie Bresson
Browse files
Merge remote-tracking branch 'origin/main' into 6.x
parents
1a6b02a3
9f969f88
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/EnvironmentsApi.java
View file @
d8777afb
...
...
@@ -93,18 +93,19 @@ public class EnvironmentsApi extends AbstractApi {
}
/**
* Create a new environment with the given name
and
external_url.
* Create a new environment with the given name
,
external_url
and tier
.
*
* <pre><code>GitLab Endpoint:POST /projects/:id/environments</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param name the name of the environment
* @param externalUrl the place to link to for this environment
* @param tier the tier of the environment
* @return the created Environment instance
* @throws GitLabApiException if any exception occurs
*/
public
Environment
createEnvironment
(
Object
projectIdOrPath
,
String
name
,
String
externalUrl
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"name"
,
name
,
true
).
withParam
(
"external_url"
,
externalUrl
);
public
Environment
createEnvironment
(
Object
projectIdOrPath
,
String
name
,
String
externalUrl
,
String
tier
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"name"
,
name
,
true
).
withParam
(
"external_url"
,
externalUrl
)
.
withParam
(
"tier"
,
tier
)
;
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"environments"
);
return
(
response
.
readEntity
(
Environment
.
class
));
...
...
@@ -119,11 +120,12 @@ public class EnvironmentsApi extends AbstractApi {
* @param environmentId the ID of the environment to update
* @param name the name of the environment
* @param externalUrl the place to link to for this environment
* @param tier the tier of the environment
* @return the created Environment instance
* @throws GitLabApiException if any exception occurs
*/
public
Environment
updateEnvironment
(
Object
projectIdOrPath
,
Long
environmentId
,
String
name
,
String
externalUrl
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"name"
,
name
).
withParam
(
"external_url"
,
externalUrl
);
public
Environment
updateEnvironment
(
Object
projectIdOrPath
,
Long
environmentId
,
String
name
,
String
externalUrl
,
String
tier
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"name"
,
name
).
withParam
(
"external_url"
,
externalUrl
)
.
withParam
(
"tier"
,
tier
)
;
Response
response
=
putWithFormData
(
Response
.
Status
.
OK
,
formData
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"environments"
,
environmentId
);
return
(
response
.
readEntity
(
Environment
.
class
));
...
...
@@ -175,4 +177,4 @@ public class EnvironmentsApi extends AbstractApi {
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"environments"
,
environmentId
,
"stop"
);
return
(
response
.
readEntity
(
Environment
.
class
));
}
}
\ No newline at end of file
}
src/main/java/org/gitlab4j/api/models/Environment.java
View file @
d8777afb
...
...
@@ -35,6 +35,7 @@ public class Environment implements Serializable {
private
String
name
;
private
String
slug
;
private
String
externalUrl
;
private
String
tier
;
private
EnvironmentState
state
;
private
Deployment
lastDeployment
;
...
...
@@ -70,6 +71,14 @@ public class Environment implements Serializable {
this
.
externalUrl
=
externalUrl
;
}
public
String
getTier
()
{
return
tier
;
}
public
void
setTier
(
String
tier
)
{
this
.
tier
=
tier
;
}
public
EnvironmentState
getState
()
{
return
state
;
}
...
...
src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java
View file @
d8777afb
...
...
@@ -38,6 +38,7 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
private
static
final
String
ENVIRONMENT_NAME
=
"gitlab4j-testing"
;
private
static
final
String
EXTERNAL_URL
=
"https:/testing.example.com/"
;
private
static
final
String
TIER
=
"testing"
;
private
static
Random
randomNumberGenerator
=
new
Random
();
public
TestEnvironmentsApi
()
{
...
...
@@ -94,7 +95,7 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
public
void
testGetEnvironments
()
throws
GitLabApiException
{
final
Environment
env
=
gitLabApi
.
getEnvironmentsApi
().
createEnvironment
(
testProject
,
getUniqueName
(),
EXTERNAL_URL
);
testProject
,
getUniqueName
(),
EXTERNAL_URL
,
TIER
);
List
<
Environment
>
envs
=
gitLabApi
.
getEnvironmentsApi
().
getEnvironments
(
testProject
);
assertTrue
(
envs
.
size
()
>
0
);
...
...
@@ -108,7 +109,7 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
public
void
testStopAndDeleteEnvironment
()
throws
GitLabApiException
{
final
Environment
env
=
gitLabApi
.
getEnvironmentsApi
().
createEnvironment
(
testProject
,
getUniqueName
(),
EXTERNAL_URL
);
testProject
,
getUniqueName
(),
EXTERNAL_URL
,
TIER
);
gitLabApi
.
getEnvironmentsApi
().
stopEnvironment
(
testProject
,
env
.
getId
());
gitLabApi
.
getEnvironmentsApi
().
deleteEnvironment
(
testProject
,
env
.
getId
());
...
...
@@ -122,7 +123,7 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
public
void
testOptionalEnvironment
()
throws
GitLabApiException
{
final
Environment
env
=
gitLabApi
.
getEnvironmentsApi
().
createEnvironment
(
testProject
,
getUniqueName
(),
EXTERNAL_URL
);
testProject
,
getUniqueName
(),
EXTERNAL_URL
,
TIER
);
Optional
<
Environment
>
optionalEnv
=
gitLabApi
.
getEnvironmentsApi
().
getOptionalEnvironment
(
testProject
,
env
.
getId
());
assertTrue
(
optionalEnv
.
isPresent
());
...
...
src/test/resources/org/gitlab4j/api/environment.json
View file @
d8777afb
...
...
@@ -4,6 +4,7 @@
"slug"
:
"review-fix-foo-dfjre3"
,
"external_url"
:
"https://review-fix-foo-dfjre3.example.gitlab.com"
,
"state"
:
"available"
,
"tier"
:
"testing"
,
"last_deployment"
:
{
"id"
:
100
,
"iid"
:
34
,
...
...
@@ -78,4 +79,4 @@
]
}
}
}
\ 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