Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini committed Aug 7, 2024
2 parents 1a6b02a + 9f969f8 commit d8777af
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/main/java/org/gitlab4j/api/EnvironmentsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,19 @@ public Optional<Environment> 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.
*
* <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));
Expand All @@ -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));
Expand Down Expand Up @@ -175,4 +177,4 @@ public Environment createEnvironment(Object projectIdOrPath, Long environmentId)
"projects", getProjectIdOrPath(projectIdOrPath), "environments", environmentId, "stop");
return (response.readEntity(Environment.class));
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/org/gitlab4j/api/models/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/org/gitlab4j/api/TestEnvironmentsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<Environment> envs = gitLabApi.getEnvironmentsApi().getEnvironments(testProject);
assertTrue(envs.size() > 0);
Expand All @@ -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());
Expand All @@ -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<Environment> optionalEnv =
gitLabApi.getEnvironmentsApi().getOptionalEnvironment(testProject, env.getId());
assertTrue(optionalEnv.isPresent());
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/org/gitlab4j/api/environment.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -78,4 +79,4 @@
]
}
}
}
}

0 comments on commit d8777af

Please sign in to comment.