diff --git a/gitlab4j-api/src/main/java/org/gitlab4j/api/GroupApi.java b/gitlab4j-api/src/main/java/org/gitlab4j/api/GroupApi.java index 155bf046e..c1aab585c 100644 --- a/gitlab4j-api/src/main/java/org/gitlab4j/api/GroupApi.java +++ b/gitlab4j-api/src/main/java/org/gitlab4j/api/GroupApi.java @@ -1781,7 +1781,7 @@ public Optional getOptionalVariable(Object groupIdOrPath, String key) public Variable createVariable(Object groupIdOrPath, String key, String value, Boolean isProtected) throws GitLabApiException { - return createVariable(groupIdOrPath, key, value, isProtected, false); + return createVariable(groupIdOrPath, key, value, isProtected, false, null); } /** @@ -1796,15 +1796,121 @@ public Variable createVariable(Object groupIdOrPath, String key, String value, B * @param masked whether the variable is masked, optional * @return a Variable instance with the newly created variable * @throws GitLabApiException if any exception occurs during execution + * @deprecated use {@link #createVariable(Object, String, String, Boolean, Boolean, String)} instead */ + @Deprecated public Variable createVariable(Object groupIdOrPath, String key, String value, Boolean isProtected, Boolean masked) throws GitLabApiException { + return createVariable(groupIdOrPath, key, value, isProtected, masked, null); + } + + /** + * Create a new group variable. + * + *
GitLab Endpoint: POST /groups/:id/variables
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required + * @param key the key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed, required + * @param value the value for the variable, required + * @param isProtected whether the variable is protected, optional + * @param masked whether the variable is masked, optional + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the newly created variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable createVariable( + Object groupIdOrPath, String key, String value, Boolean isProtected, Boolean masked, String description) + throws GitLabApiException { + + return createVariable(groupIdOrPath, key, value, null, isProtected, masked, null, description); + } + + /** + * Create a new group variable. + * + *

NOTE: Setting the environmentScope is only available on GitLab EE.

+ * + *
GitLab Endpoint: POST /groups/:id/variables
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required + * @param key the key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed, required + * @param value the value for the variable, required + * @param variableType the type of variable. Available types are: env_var (default) and file + * @param isProtected whether the variable is protected, optional + * @param masked whether the variable is masked, optional + * @param environmentScope the environment_scope of the variable, optional + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the newly created variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable createVariable( + Object groupIdOrPath, + String key, + String value, + Variable.Type variableType, + Boolean isProtected, + Boolean masked, + String environmentScope, + String description) + throws GitLabApiException { + + return createVariable( + groupIdOrPath, + key, + value, + variableType, + isProtected, + masked, + null, + null, + environmentScope, + description); + } + + /** + * Create a new group variable. + * + *

NOTE: Setting the environmentScope is only available on GitLab EE.

+ * + *
GitLab Endpoint: POST /groups/:id/variables
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required + * @param key the key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed, required + * @param value the value for the variable, required + * @param variableType the type of variable. Available types are: env_var (default) and file + * @param isProtected whether the variable is protected, optional + * @param masked whether the variable is masked, optional + * @param maskedAndHidden whether the variable is masked and hidden; can only be set at creation time, optional + * @param raw whether the variable is treated as a raw string; when false, variables in the value are expanded, optional + * @param environmentScope the environment_scope of the variable, optional + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the newly created variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable createVariable( + Object groupIdOrPath, + String key, + String value, + Variable.Type variableType, + Boolean isProtected, + Boolean masked, + Boolean maskedAndHidden, + Boolean raw, + String environmentScope, + String description) + throws GitLabApiException { + GitLabApiForm formData = new GitLabApiForm() .withParam("key", key, true) .withParam("value", value, true) + .withParam("variable_type", variableType) + .withParam("protected", isProtected) .withParam("masked", masked) - .withParam("protected", isProtected); + .withParam("masked_and_hidden", maskedAndHidden) + .withParam("raw", raw) + .withParam("environment_scope", environmentScope) + .withParam("description", description); Response response = post(Response.Status.CREATED, formData, "groups", getGroupIdOrPath(groupIdOrPath), "variables"); return (response.readEntity(Variable.class)); @@ -1825,7 +1931,7 @@ public Variable createVariable(Object groupIdOrPath, String key, String value, B public Variable updateVariable(Object groupIdOrPath, String key, String value, Boolean isProtected) throws GitLabApiException { - return updateVariable(groupIdOrPath, key, value, isProtected, false); + return updateVariable(groupIdOrPath, key, value, isProtected, false, null); } /** @@ -1840,16 +1946,110 @@ public Variable updateVariable(Object groupIdOrPath, String key, String value, B * @param masked whether the variable is masked, optional * @return a Variable instance with the updated variable * @throws GitLabApiException if any exception occurs during execution + * @deprecated use {@link #updateVariable(Object, String, String, Boolean, Boolean, String)} instead */ + @Deprecated public Variable updateVariable(Object groupIdOrPath, String key, String value, Boolean isProtected, Boolean masked) throws GitLabApiException { + return updateVariable(groupIdOrPath, key, value, isProtected, masked, null); + } + + /** + * Update a group variable. + * + *
GitLab Endpoint: PUT /groups/:id/variables/:key
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required + * @param key the key of an existing variable, required + * @param value the value for the variable, required + * @param isProtected whether the variable is protected, optional + * @param masked whether the variable is masked, optional + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the updated variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable updateVariable( + Object groupIdOrPath, String key, String value, Boolean isProtected, Boolean masked, String description) + throws GitLabApiException { + + return updateVariable(groupIdOrPath, key, value, null, isProtected, masked, null, description); + } + + /** + * Update a group variable. + * + *

NOTE: Updating the environmentScope is only available on GitLab EE.

+ * + *
GitLab Endpoint: PUT /groups/:id/variables/:key
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required + * @param key the key of an existing variable, required + * @param value the value for the variable, required + * @param variableType the type of variable. Available types are: env_var (default) and file + * @param isProtected whether the variable is protected, optional + * @param masked whether the variable is masked, optional + * @param environmentScope the environment_scope of the variable, optional + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the updated variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable updateVariable( + Object groupIdOrPath, + String key, + String value, + Variable.Type variableType, + Boolean isProtected, + Boolean masked, + String environmentScope, + String description) + throws GitLabApiException { + + return updateVariable( + groupIdOrPath, key, value, variableType, isProtected, masked, null, environmentScope, description); + } + + /** + * Update a group variable. + * + *

NOTE: Updating the environmentScope is only available on GitLab EE.

+ * + *
GitLab Endpoint: PUT /groups/:id/variables/:key
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required + * @param key the key of an existing variable, required + * @param value the value for the variable, required + * @param variableType the type of variable. Available types are: env_var (default) and file + * @param isProtected whether the variable is protected, optional + * @param masked whether the variable is masked, optional + * @param raw whether the variable is treated as a raw string; when false, variables in the value are expanded, optional + * @param environmentScope the environment_scope of the variable, optional + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the updated variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable updateVariable( + Object groupIdOrPath, + String key, + String value, + Variable.Type variableType, + Boolean isProtected, + Boolean masked, + Boolean raw, + String environmentScope, + String description) + throws GitLabApiException { + GitLabApiForm formData = new GitLabApiForm() .withParam("value", value, true) + .withParam("variable_type", variableType) + .withParam("protected", isProtected) .withParam("masked", masked) - .withParam("protected", isProtected); + .withParam("raw", raw) + .withParam("environment_scope", environmentScope) + .withParam("description", description); Response response = putWithFormData( - Response.Status.CREATED, formData, "groups", getGroupIdOrPath(groupIdOrPath), "variables", key); + Response.Status.OK, formData, "groups", getGroupIdOrPath(groupIdOrPath), "variables", key); return (response.readEntity(Variable.class)); } diff --git a/gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java b/gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java index ad69a31e5..82217e83e 100644 --- a/gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/gitlab4j-api/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -3622,7 +3622,7 @@ public Variable createVariable(Object projectIdOrPath, String key, String value, public Variable createVariable( Object projectIdOrPath, String key, String value, Boolean isProtected, String environmentScope) throws GitLabApiException { - return createVariable(projectIdOrPath, key, value, null, isProtected, null, environmentScope); + return createVariable(projectIdOrPath, key, value, null, isProtected, null, environmentScope, null); } /** @@ -3649,7 +3649,7 @@ public Variable createVariable( Boolean isProtected, Boolean isMasked) throws GitLabApiException { - return createVariable(projectIdOrPath, key, value, variableType, isProtected, isMasked, null); + return createVariable(projectIdOrPath, key, value, variableType, isProtected, isMasked, null, null); } /** @@ -3668,7 +3668,10 @@ public Variable createVariable( * @param environmentScope the environment_scope of the variable, optional * @return a Variable instance with the newly created variable * @throws GitLabApiException if any exception occurs during execution + * @deprecated use {@link #createVariable(Object, String, String, Variable.Type, Boolean, Boolean, String, String)} + * instead */ + @Deprecated public Variable createVariable( Object projectIdOrPath, String key, @@ -3678,6 +3681,83 @@ public Variable createVariable( Boolean isMasked, String environmentScope) throws GitLabApiException { + return createVariable(projectIdOrPath, key, value, variableType, isProtected, isMasked, environmentScope, null); + } + + /** + * Create a new project variable. + * + *

NOTE: Setting the environmentScope is only available on GitLab EE.

+ * + *
GitLab Endpoint: POST /projects/:id/variables
+ * + * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required + * @param key the key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed, required + * @param value the value for the variable, required + * @param variableType the type of variable. Available types are: env_var (default) and file + * @param isProtected whether the variable is protected, optional + * @param isMasked whether the variable is masked, optional + * @param environmentScope the environment_scope of the variable, optional + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the newly created variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable createVariable( + Object projectIdOrPath, + String key, + String value, + Variable.Type variableType, + Boolean isProtected, + Boolean isMasked, + String environmentScope, + String description) + throws GitLabApiException { + + return createVariable( + projectIdOrPath, + key, + value, + variableType, + isProtected, + isMasked, + null, + null, + environmentScope, + description); + } + + /** + * Create a new project variable. + * + *

NOTE: Setting the environmentScope is only available on GitLab EE.

+ * + *
GitLab Endpoint: POST /projects/:id/variables
+ * + * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required + * @param key the key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed, required + * @param value the value for the variable, required + * @param variableType the type of variable. Available types are: env_var (default) and file + * @param isProtected whether the variable is protected, optional + * @param isMasked whether the variable is masked, optional + * @param maskedAndHidden whether the variable is masked and hidden; can only be set at creation time, optional + * @param raw whether the variable is treated as a raw string; when false, variables in the value are expanded, optional + * @param environmentScope the environment_scope of the variable, optional + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the newly created variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable createVariable( + Object projectIdOrPath, + String key, + String value, + Variable.Type variableType, + Boolean isProtected, + Boolean isMasked, + Boolean maskedAndHidden, + Boolean raw, + String environmentScope, + String description) + throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() .withParam("key", key, true) @@ -3685,7 +3765,10 @@ public Variable createVariable( .withParam("variable_type", variableType) .withParam("protected", isProtected) .withParam("masked", isMasked) - .withParam("environment_scope", environmentScope); + .withParam("masked_and_hidden", maskedAndHidden) + .withParam("raw", raw) + .withParam("environment_scope", environmentScope) + .withParam("description", description); Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "variables"); return (response.readEntity(Variable.class)); @@ -3705,7 +3788,7 @@ public Variable createVariable( */ public Variable updateVariable(Object projectIdOrPath, String key, String value, Boolean isProtected) throws GitLabApiException { - return (updateVariable(projectIdOrPath, key, value, null, isProtected, null, null)); + return (updateVariable(projectIdOrPath, key, value, null, isProtected, null, null, null)); } /** @@ -3726,7 +3809,7 @@ public Variable updateVariable(Object projectIdOrPath, String key, String value, public Variable updateVariable( Object projectIdOrPath, String key, String value, Boolean isProtected, String environmentScope) throws GitLabApiException { - return updateVariable(projectIdOrPath, key, value, null, isProtected, null, environmentScope); + return updateVariable(projectIdOrPath, key, value, null, isProtected, null, environmentScope, null); } /** @@ -3753,7 +3836,7 @@ public Variable updateVariable( Boolean isProtected, Boolean masked) throws GitLabApiException { - return updateVariable(projectIdOrPath, key, value, variableType, isProtected, masked, null); + return updateVariable(projectIdOrPath, key, value, variableType, isProtected, masked, null, null); } /** @@ -3772,7 +3855,10 @@ public Variable updateVariable( * @param environmentScope the environment_scope of the variable, optional. * @return a Variable instance with the updated variable * @throws GitLabApiException if any exception occurs during execution + * @deprecated use {@link #updateVariable(Object, String, String, Variable.Type, Boolean, Boolean, String, String)} + * instead */ + @Deprecated public Variable updateVariable( Object projectIdOrPath, String key, @@ -3782,13 +3868,81 @@ public Variable updateVariable( Boolean masked, String environmentScope) throws GitLabApiException { + return updateVariable(projectIdOrPath, key, value, variableType, isProtected, masked, environmentScope, null); + } + + /** + * Update a project variable. + * + *

NOTE: Updating the environmentScope is only available on GitLab EE.

+ * + *
GitLab Endpoint: PUT /projects/:id/variables/:key
+ * + * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required + * @param key the key of an existing variable, required + * @param value the value for the variable, required + * @param variableType the type of variable. Available types are: env_var (default) and file + * @param isProtected whether the variable is protected, optional + * @param masked whether the variable is masked, optional + * @param environmentScope the environment_scope of the variable, optional. + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the updated variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable updateVariable( + Object projectIdOrPath, + String key, + String value, + Variable.Type variableType, + Boolean isProtected, + Boolean masked, + String environmentScope, + String description) + throws GitLabApiException { + + return updateVariable( + projectIdOrPath, key, value, variableType, isProtected, masked, null, environmentScope, description); + } + + /** + * Update a project variable. + * + *

NOTE: Updating the environmentScope is only available on GitLab EE.

+ * + *
GitLab Endpoint: PUT /projects/:id/variables/:key
+ * + * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required + * @param key the key of an existing variable, required + * @param value the value for the variable, required + * @param variableType the type of variable. Available types are: env_var (default) and file + * @param isProtected whether the variable is protected, optional + * @param masked whether the variable is masked, optional + * @param raw whether the variable is treated as a raw string; when false, variables in the value are expanded, optional + * @param environmentScope the environment_scope of the variable, optional + * @param description the description of the variable; must have no more than 255 characters, optional + * @return a Variable instance with the updated variable + * @throws GitLabApiException if any exception occurs during execution + */ + public Variable updateVariable( + Object projectIdOrPath, + String key, + String value, + Variable.Type variableType, + Boolean isProtected, + Boolean masked, + Boolean raw, + String environmentScope, + String description) + throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() .withParam("value", value, true) .withParam("variable_type", variableType) .withParam("protected", isProtected) .withParam("masked", masked) - .withParam("environment_scope", environmentScope); + .withParam("raw", raw) + .withParam("environment_scope", environmentScope) + .withParam("description", description); Response response = putWithFormData( Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "variables", key); return (response.readEntity(Variable.class)); diff --git a/gitlab4j-api/src/test/java/org/gitlab4j/api/TestProjectApi.java b/gitlab4j-api/src/test/java/org/gitlab4j/api/TestProjectApi.java index 2bf9eb870..39822fe99 100644 --- a/gitlab4j-api/src/test/java/org/gitlab4j/api/TestProjectApi.java +++ b/gitlab4j-api/src/test/java/org/gitlab4j/api/TestProjectApi.java @@ -846,7 +846,10 @@ public void testVariables() throws GitLabApiException { assertEquals("NO_VALUE", variable.getValue()); assertTrue(variable.getProtected()); - gitLabApi.getProjectApi().updateVariable(testProject, key, value, Variable.Type.ENV_VAR, false, true, "DEV"); + String description = "Test variable description"; + gitLabApi + .getProjectApi() + .updateVariable(testProject, key, value, Variable.Type.ENV_VAR, false, true, "DEV", description); variable = gitLabApi.getProjectApi().getVariable(testProject, key); assertNotNull(variable); @@ -854,6 +857,7 @@ public void testVariables() throws GitLabApiException { assertEquals(value, variable.getValue()); assertEquals(Variable.Type.ENV_VAR, variable.getVariableType()); assertFalse(variable.getProtected()); + assertEquals(description, variable.getDescription()); gitLabApi.getProjectApi().deleteVariable(testProject, key); variables = gitLabApi.getProjectApi().getVariablesStream(testProject); diff --git a/gitlab4j-models/src/main/java/org/gitlab4j/api/models/Variable.java b/gitlab4j-models/src/main/java/org/gitlab4j/api/models/Variable.java index 3c7160572..4cb81f65a 100644 --- a/gitlab4j-models/src/main/java/org/gitlab4j/api/models/Variable.java +++ b/gitlab4j-models/src/main/java/org/gitlab4j/api/models/Variable.java @@ -50,8 +50,16 @@ public String toString() { @JsonProperty("masked") private Boolean isMasked; + @JsonProperty("hidden") + private Boolean isHidden; + + @JsonProperty("raw") + private Boolean isRaw; + private String environmentScope; + private String description; + public Variable() {} public Variable(String key, String value) { @@ -99,6 +107,22 @@ public void setMasked(Boolean masked) { this.isMasked = masked; } + public Boolean getHidden() { + return isHidden; + } + + public void setHidden(Boolean hidden) { + this.isHidden = hidden; + } + + public Boolean getRaw() { + return isRaw; + } + + public void setRaw(Boolean raw) { + this.isRaw = raw; + } + public String getEnvironmentScope() { return environmentScope; } @@ -107,6 +131,14 @@ public void setEnvironmentScope(String environmentScope) { this.environmentScope = environmentScope; } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + @Override public String toString() { return (JacksonJson.toJsonString(this)); diff --git a/gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java b/gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java index f54ca6cb4..ec4310afa 100644 --- a/gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java +++ b/gitlab4j-models/src/test/java/org/gitlab4j/models/TestGitLabApiBeans.java @@ -429,6 +429,12 @@ public void testProjectVariables() throws Exception { assertTrue(compareJson(variables, "project-variables.json")); } + @Test + public void testGroupVariables() throws Exception { + List variables = unmarshalResourceList(Variable.class, "group-variables.json"); + assertTrue(compareJson(variables, "group-variables.json")); + } + @Test public void testJob() throws Exception { Job job = unmarshalResource(Job.class, "job.json"); diff --git a/gitlab4j-models/src/test/resources/org/gitlab4j/models/group-variables.json b/gitlab4j-models/src/test/resources/org/gitlab4j/models/group-variables.json new file mode 100644 index 000000000..735a7f78e --- /dev/null +++ b/gitlab4j-models/src/test/resources/org/gitlab4j/models/group-variables.json @@ -0,0 +1,26 @@ +[ + { + "key": "TEST_VARIABLE_1", + "variable_type": "env_var", + "value": "TEST_1", + "protected": false, + "masked": false, + "hidden": false, + "raw": false, + "environment_scope": "*", + "description": "The first test variable" + }, + { + "key": "TEST_VARIABLE_2", + "variable_type": "file", + "value": "TEST_2", + "masked": true, + "hidden": true, + "raw": true, + "description": "The second test variable" + }, + { + "key": "TEST_VARIABLE_3", + "value": "TEST_3" + } +] diff --git a/gitlab4j-models/src/test/resources/org/gitlab4j/models/project-variables.json b/gitlab4j-models/src/test/resources/org/gitlab4j/models/project-variables.json index c2d9bd0cf..c37216b5b 100644 --- a/gitlab4j-models/src/test/resources/org/gitlab4j/models/project-variables.json +++ b/gitlab4j-models/src/test/resources/org/gitlab4j/models/project-variables.json @@ -3,12 +3,20 @@ "key": "TEST_VARIABLE_1", "value": "TEST_1", "protected": true, - "environment_scope": "*" + "masked": false, + "hidden": false, + "raw": false, + "environment_scope": "*", + "description": "The first test variable" }, { "key": "TEST_VARIABLE_2", "value": "TEST_2", - "protected": false + "protected": false, + "masked": true, + "hidden": true, + "raw": true, + "description": "The second test variable" }, { "key": "TEST_VARIABLE_3",