From 9f969f8801ea011a4d9bf7745cfa3202562f631a Mon Sep 17 00:00:00 2001 From: Ivaylo Rusev <71213671+Rusev11@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:40:41 +0300 Subject: [PATCH] Add attribute 'tier' to Environment model (#1146) --------- Co-authored-by: ivaylorusev Co-authored-by: Jeremie Bresson --- .../org/gitlab4j/api/EnvironmentsApi.java | 43 +++++++++++++++++-- .../org/gitlab4j/api/models/Environment.java | 9 ++++ .../org/gitlab4j/api/TestEnvironmentsApi.java | 7 +-- .../org/gitlab4j/api/environment.json | 3 +- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/EnvironmentsApi.java b/src/main/java/org/gitlab4j/api/EnvironmentsApi.java index 6eca51277..2816f18ae 100644 --- a/src/main/java/org/gitlab4j/api/EnvironmentsApi.java +++ b/src/main/java/org/gitlab4j/api/EnvironmentsApi.java @@ -102,9 +102,27 @@ public Optional getOptionalEnvironment(Object projectIdOrPath, Long * @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. + * + *
GitLab Endpoint:POST /projects/:id/environments
+ * + * @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 Environment createEnvironment(Object projectIdOrPath, String name, String * @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. + * + *
GitLab Endpoint:POST /projects/:id/environments
+ * + * @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 Environment createEnvironment(Object projectIdOrPath, Long environmentId) "projects", getProjectIdOrPath(projectIdOrPath), "environments", environmentId, "stop"); return (response.readEntity(Environment.class)); } -} \ No newline at end of file +} diff --git a/src/main/java/org/gitlab4j/api/models/Environment.java b/src/main/java/org/gitlab4j/api/models/Environment.java index 1a2ecb596..74a298574 100644 --- a/src/main/java/org/gitlab4j/api/models/Environment.java +++ b/src/main/java/org/gitlab4j/api/models/Environment.java @@ -35,6 +35,7 @@ public String toString() { private String name; private String slug; private String externalUrl; + private String tier; private EnvironmentState state; private Deployment lastDeployment; @@ -70,6 +71,14 @@ public void setExternalUrl(String externalUrl) { this.externalUrl = externalUrl; } + public String getTier() { + return tier; + } + + public void setTier(String tier) { + this.tier = tier; + } + public EnvironmentState getState() { return state; } diff --git a/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java b/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java index f94eb1921..a142eb02d 100644 --- a/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java +++ b/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java @@ -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 @@ private static String getUniqueName() { public void testGetEnvironments() throws GitLabApiException { final Environment env = gitLabApi.getEnvironmentsApi().createEnvironment( - testProject, getUniqueName(), EXTERNAL_URL); + testProject, getUniqueName(), EXTERNAL_URL, TIER); List envs = gitLabApi.getEnvironmentsApi().getEnvironments(testProject); assertTrue(envs.size() > 0); @@ -108,7 +109,7 @@ public void testGetEnvironments() throws GitLabApiException { 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 void testStopAndDeleteEnvironment() throws GitLabApiException { public void testOptionalEnvironment() throws GitLabApiException { final Environment env = gitLabApi.getEnvironmentsApi().createEnvironment( - testProject, getUniqueName(), EXTERNAL_URL); + testProject, getUniqueName(), EXTERNAL_URL, TIER); Optional optionalEnv = gitLabApi.getEnvironmentsApi().getOptionalEnvironment(testProject, env.getId()); assertTrue(optionalEnv.isPresent()); diff --git a/src/test/resources/org/gitlab4j/api/environment.json b/src/test/resources/org/gitlab4j/api/environment.json index 03a64d24c..ff77773da 100644 --- a/src/test/resources/org/gitlab4j/api/environment.json +++ b/src/test/resources/org/gitlab4j/api/environment.json @@ -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 +}