Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit 8f72222

Browse files
authored
Merge pull request #1995 from andersparslov/get-scoped-group-variables
Get scoped group variables
2 parents f97a106 + 084e9c4 commit 8f72222

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

group_variables.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,27 @@ func (s *GroupVariablesService) ListVariables(gid interface{}, opt *ListGroupVar
8282
return vs, resp, nil
8383
}
8484

85+
// GetGroupVariableOptions represents the available GetVariable()
86+
// options.
87+
//
88+
// GitLab API docs:
89+
// https://docs.gitlab.com/ee/api/group_level_variables.html#show-variable-details
90+
type GetGroupVariableOptions struct {
91+
Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"`
92+
}
93+
8594
// GetVariable gets a variable.
8695
//
8796
// GitLab API docs:
8897
// https://docs.gitlab.com/ee/api/group_level_variables.html#show-variable-details
89-
func (s *GroupVariablesService) GetVariable(gid interface{}, key string, options ...RequestOptionFunc) (*GroupVariable, *Response, error) {
98+
func (s *GroupVariablesService) GetVariable(gid interface{}, key string, opt *GetGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) {
9099
group, err := parseID(gid)
91100
if err != nil {
92101
return nil, nil, err
93102
}
94103
u := fmt.Sprintf("groups/%s/variables/%s", PathEscape(group), url.PathEscape(key))
95104

96-
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
105+
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
97106
if err != nil {
98107
return nil, nil, err
99108
}

group_variables_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ func TestGetGroupVariable(t *testing.T) {
5757
mux.HandleFunc("/api/v4/groups/1/variables/TEST_VARIABLE_1",
5858
func(w http.ResponseWriter, r *http.Request) {
5959
testMethod(t, r, http.MethodGet)
60+
testParams(t, r, "filter%5Benvironment_scope%5D=prod")
6061
fmt.Fprint(w, `{"key": "TEST_VARIABLE_1","value": "test1","protected": false,"masked": true}`)
6162
})
6263

63-
variable, _, err := client.GroupVariables.GetVariable(1, "TEST_VARIABLE_1")
64+
variable, _, err := client.GroupVariables.GetVariable(1, "TEST_VARIABLE_1", &GetGroupVariableOptions{Filter: &VariableFilter{EnvironmentScope: "prod"}})
6465
if err != nil {
6566
t.Errorf("GroupVariables.GetVariable returned error: %v", err)
6667
}

0 commit comments

Comments
 (0)