Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yogeshlonkar
Copy link

No description provided.

@timofurrer timofurrer self-requested a review November 21, 2024 19:18
Copy link
Collaborator

@timofurrer timofurrer left a 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 🏓

project_variables.go Outdated Show resolved Hide resolved
project_variables.go Outdated Show resolved Hide resolved
@yogeshlonkar yogeshlonkar changed the title Add hidden field to ProjectVariable struct Add masked_and_hidden field to project create and get api Dec 3, 2024
@yogeshlonkar yogeshlonkar changed the title Add masked_and_hidden field to project create and get api Add masked_and_hidden field to project variable create and get api Dec 3, 2024
Copy link
Collaborator

@RicePatrick RicePatrick left a 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"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@RicePatrick
Copy link
Collaborator

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants