Commit 7537b744 authored by Sander van Harmelen's avatar Sander van Harmelen

Remove the now obsolete build variables

parent 7846dae9
......@@ -20,10 +20,6 @@ incompatible changes that were needed to fully support the V4 Gitlab API.
This API client package covers most of the existing Gitlab API calls and is updated regularly
to add new and/or missing endpoints. Currently the following services are supported:
- [ ] Discussions (threaded comments)
- [ ] Epic Issues
- [ ] Epics
- [ ] Geo Nodes
- [x] Award Emojis
- [x] Branches
- [x] Broadcast Messages
......@@ -32,9 +28,13 @@ to add new and/or missing endpoints. Currently the following services are suppor
- [x] Custom Attributes
- [x] Deploy Keys
- [x] Deployments
- [ ] Discussions (threaded comments)
- [x] Environments
- [ ] Epic Issues
- [ ] Epics
- [x] Events
- [x] Feature Flags
- [ ] Geo Nodes
- [x] GitLab CI Config Templates
- [x] Gitignores Templates
- [x] Group Access Requests
......
package gitlab
import (
"fmt"
)
// BuildVariablesService handles communication with the project variables related methods
// of the Gitlab API
//
// Gitlab API Docs : https://docs.gitlab.com/ce/api/build_variables.html
type BuildVariablesService struct {
client *Client
}
// BuildVariable represents a variable available for each build of the given project
//
// Gitlab API Docs : https://docs.gitlab.com/ce/api/build_variables.html
type BuildVariable struct {
Key string `json:"key"`
Value string `json:"value"`
Protected bool `json:"protected"`
}
func (v BuildVariable) String() string {
return Stringify(v)
}
// ListBuildVariablesOptions are the parameters to ListBuildVariables()
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#list-project-variables
type ListBuildVariablesOptions ListOptions
// ListBuildVariables gets the a list of project variables in a project
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#list-project-variables
func (s *BuildVariablesService) ListBuildVariables(pid interface{}, opts *ListBuildVariablesOptions, options ...OptionFunc) ([]*BuildVariable, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/variables", pathEscape(project))
req, err := s.client.NewRequest("GET", u, opts, options)
if err != nil {
return nil, nil, err
}
var v []*BuildVariable
resp, err := s.client.Do(req, &v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// GetBuildVariable gets a single project variable of a project
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#show-variable-details
func (s *BuildVariablesService) GetBuildVariable(pid interface{}, key string, options ...OptionFunc) (*BuildVariable, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/variables/%s", pathEscape(project), key)
req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
return nil, nil, err
}
v := new(BuildVariable)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// CreateBuildVariableOptions are the parameters to CreateBuildVariable()
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#create-variable
type CreateBuildVariableOptions struct {
Key *string `url:"key" json:"key"`
Value *string `url:"value" json:"value"`
Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
}
// CreateBuildVariable creates a variable for a given project
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#create-variable
func (s *BuildVariablesService) CreateBuildVariable(pid interface{}, opt *CreateBuildVariableOptions, options ...OptionFunc) (*BuildVariable, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/variables", pathEscape(project))
req, err := s.client.NewRequest("POST", u, opt, options)
if err != nil {
return nil, nil, err
}
v := new(BuildVariable)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// UpdateBuildVariableOptions are the parameters to UpdateBuildVariable()
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#update-variable
type UpdateBuildVariableOptions struct {
Key *string `url:"key" json:"key"`
Value *string `url:"value" json:"value"`
Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
}
// UpdateBuildVariable updates an existing project variable
// The variable key must exist
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#update-variable
func (s *BuildVariablesService) UpdateBuildVariable(pid interface{}, key string, opt *UpdateBuildVariableOptions, options ...OptionFunc) (*BuildVariable, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/variables/%s", pathEscape(project), key)
req, err := s.client.NewRequest("PUT", u, opt, options)
if err != nil {
return nil, nil, err
}
v := new(BuildVariable)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// RemoveBuildVariable removes a project variable of a given project identified by its key
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#remove-variable
func (s *BuildVariablesService) RemoveBuildVariable(pid interface{}, key string, options ...OptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/variables/%s", pathEscape(project), key)
req, err := s.client.NewRequest("DELETE", u, nil, options)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
const (
myKey = "MY_KEY"
myValue = "MY_VALUE"
myKey2 = "MY_KEY2"
myValue2 = "MY_VALUE2"
myNewValue = "MY_NEW_VALUE"
)
func TestListBuildVariables(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/variables", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprintf(w,
`[{"key":"%s","value":"%s"},{"key":"%s","value":"%s"}]`, myKey, myValue, myKey2, myValue2)
})
variables, _, err := client.BuildVariables.ListBuildVariables(1, nil)
if err != nil {
t.Errorf("ListBuildVariables returned error: %v", err)
}
want := []*BuildVariable{{Key: myKey, Value: myValue}, {Key: myKey2, Value: myValue2}}
if !reflect.DeepEqual(want, variables) {
t.Errorf("ListBuildVariables returned %+v, want %+v", variables, want)
}
}
func TestGetBuildVariable(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/variables/"+myKey, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprintf(w, `{"key":"%s","value":"%s"}`, myKey, myValue)
})
variable, _, err := client.BuildVariables.GetBuildVariable(1, myKey)
if err != nil {
t.Errorf("GetBuildVariable returned error: %v", err)
}
want := &BuildVariable{Key: myKey, Value: myValue}
if !reflect.DeepEqual(want, variable) {
t.Errorf("GetBuildVariable returned %+v, want %+v", variable, want)
}
}
func TestCreateBuildVariable(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/variables", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprintf(w, `{"key":"%s","value":"%s", "protected": false}`, myKey, myValue)
})
opt := &CreateBuildVariableOptions{String(myKey), String(myValue), Bool(false)}
variable, _, err := client.BuildVariables.CreateBuildVariable(1, opt)
if err != nil {
t.Errorf("CreateBuildVariable returned error: %v", err)
}
want := &BuildVariable{Key: myKey, Value: myValue, Protected: false}
if !reflect.DeepEqual(want, variable) {
t.Errorf("CreateBuildVariable returned %+v, want %+v", variable, want)
}
}
func TestUpdateBuildVariable(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/variables/"+myKey, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
fmt.Fprintf(w, `{"key":"%s","value":"%s", "protected": false}`, myKey, myNewValue)
})
opt := &UpdateBuildVariableOptions{String(myKey), String(myNewValue), Bool(false)}
variable, _, err := client.BuildVariables.UpdateBuildVariable(1, myKey, opt)
if err != nil {
t.Errorf("UpdateBuildVariable returned error: %v", err)
}
want := &BuildVariable{Key: myKey, Value: myNewValue, Protected: false}
if !reflect.DeepEqual(want, variable) {
t.Errorf("UpdateBuildVariable returned %+v, want %+v", variable, want)
}
}
func TestRemoveBuildVariable(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/variables/"+myKey, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
_, err := client.BuildVariables.RemoveBuildVariable(1, myKey)
if err != nil {
t.Errorf("RemoveBuildVariable returned error: %v", err)
}
}
......@@ -304,7 +304,6 @@ type Client struct {
Boards *IssueBoardsService
Branches *BranchesService
BroadcastMessage *BroadcastMessagesService
BuildVariables *BuildVariablesService
CIYMLTemplate *CIYMLTemplatesService
Commits *CommitsService
ContainerRegistry *ContainerRegistryService
......@@ -454,7 +453,6 @@ func newClient(httpClient *http.Client) *Client {
c.Boards = &IssueBoardsService{client: c}
c.Branches = &BranchesService{client: c}
c.BroadcastMessage = &BroadcastMessagesService{client: c}
c.BuildVariables = &BuildVariablesService{client: c}
c.CIYMLTemplate = &CIYMLTemplatesService{client: c}
c.Commits = &CommitsService{client: c}
c.ContainerRegistry = &ContainerRegistryService{client: c}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment