123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package gitlab
- import (
- "fmt"
- "net/url"
- )
- type ProjectVariablesService struct {
- client *Client
- }
- type ProjectVariable struct {
- Key string `json:"key"`
- Value string `json:"value"`
- Protected bool `json:"protected"`
- EnvironmentScope string `json:"environment_scope"`
- }
- func (v ProjectVariable) String() string {
- return Stringify(v)
- }
- func (s *ProjectVariablesService) ListVariables(pid interface{}, options ...OptionFunc) ([]*ProjectVariable, *Response, error) {
- project, err := parseID(pid)
- if err != nil {
- return nil, nil, err
- }
- u := fmt.Sprintf("projects/%s/variables", url.QueryEscape(project))
- req, err := s.client.NewRequest("GET", u, nil, options)
- if err != nil {
- return nil, nil, err
- }
- var vs []*ProjectVariable
- resp, err := s.client.Do(req, &vs)
- if err != nil {
- return nil, resp, err
- }
- return vs, resp, err
- }
- func (s *ProjectVariablesService) GetVariable(pid interface{}, key string, options ...OptionFunc) (*ProjectVariable, *Response, error) {
- project, err := parseID(pid)
- if err != nil {
- return nil, nil, err
- }
- u := fmt.Sprintf("projects/%s/variables/%s", url.QueryEscape(project), url.QueryEscape(key))
- req, err := s.client.NewRequest("GET", u, nil, options)
- if err != nil {
- return nil, nil, err
- }
- v := new(ProjectVariable)
- resp, err := s.client.Do(req, v)
- if err != nil {
- return nil, resp, err
- }
- return v, resp, err
- }
- type CreateVariableOptions struct {
- Key *string `url:"key,omitempty" json:"key,omitempty"`
- Value *string `url:"value,omitempty" json:"value,omitempty"`
- Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
- EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
- }
- func (s *ProjectVariablesService) CreateVariable(pid interface{}, opt *CreateVariableOptions, options ...OptionFunc) (*ProjectVariable, *Response, error) {
- project, err := parseID(pid)
- if err != nil {
- return nil, nil, err
- }
- u := fmt.Sprintf("projects/%s/variables", url.QueryEscape(project))
- req, err := s.client.NewRequest("POST", u, opt, options)
- if err != nil {
- return nil, nil, err
- }
- v := new(ProjectVariable)
- resp, err := s.client.Do(req, v)
- if err != nil {
- return nil, resp, err
- }
- return v, resp, err
- }
- type UpdateVariableOptions struct {
- Value *string `url:"value,omitempty" json:"value,omitempty"`
- Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
- EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
- }
- func (s *ProjectVariablesService) UpdateVariable(pid interface{}, key string, opt *UpdateVariableOptions, options ...OptionFunc) (*ProjectVariable, *Response, error) {
- project, err := parseID(pid)
- if err != nil {
- return nil, nil, err
- }
- u := fmt.Sprintf("projects/%s/variables/%s",
- url.QueryEscape(project),
- url.QueryEscape(key),
- )
- req, err := s.client.NewRequest("PUT", u, opt, options)
- if err != nil {
- return nil, nil, err
- }
- v := new(ProjectVariable)
- resp, err := s.client.Do(req, v)
- if err != nil {
- return nil, resp, err
- }
- return v, resp, err
- }
- func (s *ProjectVariablesService) RemoveVariable(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",
- url.QueryEscape(project),
- url.QueryEscape(key),
- )
- req, err := s.client.NewRequest("DELETE", u, nil, options)
- if err != nil {
- return nil, err
- }
- return s.client.Do(req, nil)
- }
|