Skip to content

Commit 9f969f8

Browse files
Rusev11ivaylorusevjmini
authored
Add attribute 'tier' to Environment model (#1146)
--------- Co-authored-by: ivaylorusev <[email protected]> Co-authored-by: Jeremie Bresson <[email protected]>
1 parent bff0b31 commit 9f969f8

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

src/main/java/org/gitlab4j/api/EnvironmentsApi.java

+40-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,27 @@ public Optional<Environment> getOptionalEnvironment(Object projectIdOrPath, Long
102102
* @param externalUrl the place to link to for this environment
103103
* @return the created Environment instance
104104
* @throws GitLabApiException if any exception occurs
105+
* @deprecated use {@link #createEnvironment(Object, String, String, String)} instead
105106
*/
107+
@Deprecated
106108
public Environment createEnvironment(Object projectIdOrPath, String name, String externalUrl) throws GitLabApiException {
107-
GitLabApiForm formData = new GitLabApiForm().withParam("name", name, true).withParam("external_url", externalUrl);
109+
return createEnvironment(projectIdOrPath, name, externalUrl, null);
110+
}
111+
112+
/**
113+
* Create a new environment with the given name, external_url and tier.
114+
*
115+
* <pre><code>GitLab Endpoint:POST /projects/:id/environments</code></pre>
116+
*
117+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
118+
* @param name the name of the environment
119+
* @param externalUrl the place to link to for this environment
120+
* @param tier the tier of the environment
121+
* @return the created Environment instance
122+
* @throws GitLabApiException if any exception occurs
123+
*/
124+
public Environment createEnvironment(Object projectIdOrPath, String name, String externalUrl, String tier) throws GitLabApiException {
125+
GitLabApiForm formData = new GitLabApiForm().withParam("name", name, true).withParam("external_url", externalUrl).withParam("tier", tier);
108126
Response response = post(Response.Status.CREATED, formData,
109127
"projects", getProjectIdOrPath(projectIdOrPath), "environments");
110128
return (response.readEntity(Environment.class));
@@ -121,9 +139,28 @@ public Environment createEnvironment(Object projectIdOrPath, String name, String
121139
* @param externalUrl the place to link to for this environment
122140
* @return the created Environment instance
123141
* @throws GitLabApiException if any exception occurs
142+
* @deprecated use {@link #updateEnvironment(Object, Long, String, String, String)} instead
124143
*/
144+
@Deprecated
125145
public Environment updateEnvironment(Object projectIdOrPath, Long environmentId, String name, String externalUrl) throws GitLabApiException {
126-
GitLabApiForm formData = new GitLabApiForm().withParam("name", name).withParam("external_url", externalUrl);
146+
return updateEnvironment(projectIdOrPath, environmentId, name, externalUrl, null);
147+
}
148+
149+
/**
150+
* Update an existing environment.
151+
*
152+
* <pre><code>GitLab Endpoint:POST /projects/:id/environments</code></pre>
153+
*
154+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
155+
* @param environmentId the ID of the environment to update
156+
* @param name the name of the environment
157+
* @param externalUrl the place to link to for this environment
158+
* @param tier the tier of the environment
159+
* @return the created Environment instance
160+
* @throws GitLabApiException if any exception occurs
161+
*/
162+
public Environment updateEnvironment(Object projectIdOrPath, Long environmentId, String name, String externalUrl, String tier) throws GitLabApiException {
163+
GitLabApiForm formData = new GitLabApiForm().withParam("name", name).withParam("external_url", externalUrl).withParam("tier", tier);
127164
Response response = putWithFormData(Response.Status.OK, formData, formData,
128165
"projects", getProjectIdOrPath(projectIdOrPath), "environments", environmentId);
129166
return (response.readEntity(Environment.class));
@@ -175,4 +212,4 @@ public Environment createEnvironment(Object projectIdOrPath, Long environmentId)
175212
"projects", getProjectIdOrPath(projectIdOrPath), "environments", environmentId, "stop");
176213
return (response.readEntity(Environment.class));
177214
}
178-
}
215+
}

src/main/java/org/gitlab4j/api/models/Environment.java

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public String toString() {
3535
private String name;
3636
private String slug;
3737
private String externalUrl;
38+
private String tier;
3839
private EnvironmentState state;
3940
private Deployment lastDeployment;
4041

@@ -70,6 +71,14 @@ public void setExternalUrl(String externalUrl) {
7071
this.externalUrl = externalUrl;
7172
}
7273

74+
public String getTier() {
75+
return tier;
76+
}
77+
78+
public void setTier(String tier) {
79+
this.tier = tier;
80+
}
81+
7382
public EnvironmentState getState() {
7483
return state;
7584
}

src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class TestEnvironmentsApi extends AbstractIntegrationTest {
3838

3939
private static final String ENVIRONMENT_NAME = "gitlab4j-testing";
4040
private static final String EXTERNAL_URL = "https:/testing.example.com/";
41+
private static final String TIER = "testing";
4142
private static Random randomNumberGenerator = new Random();
4243

4344
public TestEnvironmentsApi() {
@@ -94,7 +95,7 @@ private static String getUniqueName() {
9495
public void testGetEnvironments() throws GitLabApiException {
9596

9697
final Environment env = gitLabApi.getEnvironmentsApi().createEnvironment(
97-
testProject, getUniqueName(), EXTERNAL_URL);
98+
testProject, getUniqueName(), EXTERNAL_URL, TIER);
9899

99100
List<Environment> envs = gitLabApi.getEnvironmentsApi().getEnvironments(testProject);
100101
assertTrue(envs.size() > 0);
@@ -108,7 +109,7 @@ public void testGetEnvironments() throws GitLabApiException {
108109
public void testStopAndDeleteEnvironment() throws GitLabApiException {
109110

110111
final Environment env = gitLabApi.getEnvironmentsApi().createEnvironment(
111-
testProject, getUniqueName(), EXTERNAL_URL);
112+
testProject, getUniqueName(), EXTERNAL_URL, TIER);
112113

113114
gitLabApi.getEnvironmentsApi().stopEnvironment(testProject, env.getId());
114115
gitLabApi.getEnvironmentsApi().deleteEnvironment(testProject, env.getId());
@@ -122,7 +123,7 @@ public void testStopAndDeleteEnvironment() throws GitLabApiException {
122123
public void testOptionalEnvironment() throws GitLabApiException {
123124

124125
final Environment env = gitLabApi.getEnvironmentsApi().createEnvironment(
125-
testProject, getUniqueName(), EXTERNAL_URL);
126+
testProject, getUniqueName(), EXTERNAL_URL, TIER);
126127
Optional<Environment> optionalEnv =
127128
gitLabApi.getEnvironmentsApi().getOptionalEnvironment(testProject, env.getId());
128129
assertTrue(optionalEnv.isPresent());

src/test/resources/org/gitlab4j/api/environment.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"slug": "review-fix-foo-dfjre3",
55
"external_url": "https://review-fix-foo-dfjre3.example.gitlab.com",
66
"state": "available",
7+
"tier": "testing",
78
"last_deployment": {
89
"id": 100,
910
"iid": 34,
@@ -78,4 +79,4 @@
7879
]
7980
}
8081
}
81-
}
82+
}

0 commit comments

Comments
 (0)