From 6cd253ca52a3eaaa8e1a87e07d4b1b3d98ea32a0 Mon Sep 17 00:00:00 2001 From: ivaylorusev Date: Fri, 26 Jul 2024 15:47:38 +0300 Subject: [PATCH 1/6] Fetch environment's property 'tier' --- src/main/java/org/gitlab4j/api/models/Environment.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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; } From 4570ba97412ed42fda73c3762a3fc59cd79e203e Mon Sep 17 00:00:00 2001 From: ivaylorusev Date: Tue, 30 Jul 2024 12:27:50 +0300 Subject: [PATCH 2/6] Add environment's property 'tier' to EnvironmentsApi class --- .../java/org/gitlab4j/api/EnvironmentsApi.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/EnvironmentsApi.java b/src/main/java/org/gitlab4j/api/EnvironmentsApi.java index 6eca51277..54565bc27 100644 --- a/src/main/java/org/gitlab4j/api/EnvironmentsApi.java +++ b/src/main/java/org/gitlab4j/api/EnvironmentsApi.java @@ -93,18 +93,19 @@ public Optional getOptionalEnvironment(Object projectIdOrPath, Long } /** - * Create a new environment with the given name and external_url. + * 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) 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 Environment createEnvironment(Object projectIdOrPath, String name, String * @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 Environment createEnvironment(Object projectIdOrPath, Long environmentId) "projects", getProjectIdOrPath(projectIdOrPath), "environments", environmentId, "stop"); return (response.readEntity(Environment.class)); } -} \ No newline at end of file +} From 21fe6f04a9062cc26629a09eff9f7cccb3184047 Mon Sep 17 00:00:00 2001 From: ivaylorusev Date: Tue, 30 Jul 2024 12:28:06 +0300 Subject: [PATCH 3/6] Fix tests --- src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java b/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java index f94eb1921..e3044d8c3 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 = "development"; 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()); From 6ea87f0f7d77f37f7f836e8f37f30636a22faa1d Mon Sep 17 00:00:00 2001 From: ivaylorusev Date: Tue, 30 Jul 2024 12:38:32 +0300 Subject: [PATCH 4/6] Rename test environment's tier --- src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java b/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java index e3044d8c3..a142eb02d 100644 --- a/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java +++ b/src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java @@ -38,7 +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 = "development"; + private static final String TIER = "testing"; private static Random randomNumberGenerator = new Random(); public TestEnvironmentsApi() { From f1797c5aa77acfaf19303db6291e217b4f6eca5d Mon Sep 17 00:00:00 2001 From: ivaylorusev Date: Tue, 6 Aug 2024 11:32:26 +0300 Subject: [PATCH 5/6] Add the new environment's attribute 'tier' to test resources --- src/test/resources/org/gitlab4j/api/environment.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 +} From 066cfd71a4cc4a2901c223fc05aac619fda4c63e Mon Sep 17 00:00:00 2001 From: Jeremie Bresson Date: Wed, 7 Aug 2024 08:14:53 +0200 Subject: [PATCH 6/6] Add backward compatible methods --- .../org/gitlab4j/api/EnvironmentsApi.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/EnvironmentsApi.java b/src/main/java/org/gitlab4j/api/EnvironmentsApi.java index 54565bc27..2816f18ae 100644 --- a/src/main/java/org/gitlab4j/api/EnvironmentsApi.java +++ b/src/main/java/org/gitlab4j/api/EnvironmentsApi.java @@ -92,6 +92,23 @@ public Optional getOptionalEnvironment(Object projectIdOrPath, Long } } + /** + * Create a new environment with the given name and external_url. + * + *
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 + * @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 { + return createEnvironment(projectIdOrPath, name, externalUrl, null); + } + /** * Create a new environment with the given name, external_url and tier. * @@ -111,6 +128,24 @@ public Environment createEnvironment(Object projectIdOrPath, String name, String return (response.readEntity(Environment.class)); } + /** + * 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 + * @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 { + return updateEnvironment(projectIdOrPath, environmentId, name, externalUrl, null); + } + /** * Update an existing environment. *