-
Notifications
You must be signed in to change notification settings - Fork 963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add masked_and_hidden field to project variable create and get api #2065
base: main
Are you sure you want to change the base?
Add masked_and_hidden field to project variable create and get api #2065
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yogeshlonkar thanks for the contribution 🤝 I've left some clarification questions on the correctness of the field / field naming. Back to you 🏓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and tested this against a locally running GitLab with the 2 suggested changes, and the tests pass. If you'd please make those changes, I'm good to merge.
@@ -41,6 +41,7 @@ type ProjectVariable struct { | |||
VariableType VariableTypeValue `json:"variable_type"` | |||
Protected bool `json:"protected"` | |||
Masked bool `json:"masked"` | |||
MaskedAndHidden bool `json:"masked_and_hidden"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaskedAndHidden bool `json:"masked_and_hidden"` | |
Masked bool `json:"masked"` |
When reading the variable, you get the masked
result back, not masked_and_hidden
- Masked and Hidden have a value of true
for this.
@@ -132,6 +133,7 @@ type CreateProjectVariableOptions struct { | |||
Description *string `url:"description,omitempty" json:"description,omitempty"` | |||
EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"` | |||
Masked *bool `url:"masked,omitempty" json:"masked,omitempty"` | |||
MaskedAndHidden *bool `url:"masked_and_hidden,omitempty" json:"masked,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaskedAndHidden *bool `url:"masked_and_hidden,omitempty" json:"masked,omitempty"` | |
MaskedAndHidden *bool `url:"masked_and_hidden,omitempty" json:"masked_and_hidden,omitempty"` |
Similarly when creating the variable, we need to pass in masked_and_hidden
whether we're using the URL or the JSON, so this value needs to be updated.
Here is the test I used to test the above 2 suggestions: func TestProjectVariablesService_MaskAndHidden_RealGitLab(t *testing.T) {
client, err := NewClient("<token>",
WithBaseURL("http://localhost:8085"),
)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
// create a project
project, _, err := client.Projects.CreateProject(&CreateProjectOptions{
Name: Ptr(fmt.Sprintf("test-%d", time.Now().UnixMicro())),
})
if err != nil {
t.Fatalf("Failed to create project: %v", err)
}
projectVar, _, err := client.ProjectVariables.CreateVariable(project.ID, &CreateProjectVariableOptions{
Key: Ptr("test"),
Value: Ptr("testtesttest"), // must have a min of 8 characters
MaskedAndHidden: Ptr(true),
})
if err != nil {
t.Fatalf("Failed to create project variable: %v", err)
}
assert.True(t, projectVar.Hidden)
} |
No description provided.