Unverified Commit 9f969f88 authored by Ivaylo Rusev's avatar Ivaylo Rusev Committed by GitHub
Browse files

Add attribute 'tier' to Environment model (#1146)



---------

Co-authored-by: default avatarivaylorusev <ivaylo.rusev@paysafe.com>
Co-authored-by: default avatarJeremie Bresson <jeremie.bresson@unblu.com>
parent bff0b319
......@@ -102,9 +102,27 @@ public class EnvironmentsApi extends AbstractApi {
* @param externalUrl the place to link to for this environment
* @return the created Environment instance
* @throws GitLabApiException if any exception occurs
* @deprecated use {@link #createEnvironment(Object, String, String, String)} instead
*/
@Deprecated
public Environment createEnvironment(Object projectIdOrPath, String name, String externalUrl) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("name", name, true).withParam("external_url", externalUrl);
return createEnvironment(projectIdOrPath, name, externalUrl, null);
}
/**
* 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, 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));
......@@ -121,9 +139,28 @@ public class EnvironmentsApi extends AbstractApi {
* @param externalUrl the place to link to for this environment
* @return the created Environment instance
* @throws GitLabApiException if any exception occurs
* @deprecated use {@link #updateEnvironment(Object, Long, String, String, String)} instead
*/
@Deprecated
public Environment updateEnvironment(Object projectIdOrPath, Long environmentId, String name, String externalUrl) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("name", name).withParam("external_url", externalUrl);
return updateEnvironment(projectIdOrPath, environmentId, name, externalUrl, null);
}
/**
* Update an existing environment.
*
* <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 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, 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 +212,4 @@ public class EnvironmentsApi extends AbstractApi {
"projects", getProjectIdOrPath(projectIdOrPath), "environments", environmentId, "stop");
return (response.readEntity(Environment.class));
}
}
\ No newline at end of file
}
......@@ -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;
}
......
......@@ -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());
......
......@@ -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
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment