From 1f9493ab6b3ea606bf1fa161ff432f077edda671 Mon Sep 17 00:00:00 2001 From: Wijk Date: Thu, 15 Aug 2019 13:11:00 +0200 Subject: [PATCH 1/3] Bring variable support up to date (support: variable_type, masked and environment_scope) --- gitlab/resource_gitlab_group_variable.go | 27 ++++++++----- gitlab/resource_gitlab_group_variable_test.go | 1 + gitlab/resource_gitlab_project_variable.go | 40 +++++++++++++++++-- .../resource_gitlab_project_variable_test.go | 1 + gitlab/util.go | 28 +++++++++++++ website/docs/r/group_variable.html.markdown | 2 + website/docs/r/project_variable.html.markdown | 6 +++ 7 files changed, 92 insertions(+), 13 deletions(-) diff --git a/gitlab/resource_gitlab_group_variable.go b/gitlab/resource_gitlab_group_variable.go index 0271ca97b..cee351a30 100644 --- a/gitlab/resource_gitlab_group_variable.go +++ b/gitlab/resource_gitlab_group_variable.go @@ -34,6 +34,12 @@ func resourceGitlabGroupVariable() *schema.Resource { Required: true, Sensitive: true, }, + "variable_type": { + Type: schema.TypeString, + Optional: true, + Default: "env_var", + ValidateFunc: StringIsGitlabVariableType(), + }, "protected": { Type: schema.TypeBool, Optional: true, @@ -49,13 +55,14 @@ func resourceGitlabGroupVariableCreate(d *schema.ResourceData, meta interface{}) group := d.Get("group").(string) key := d.Get("key").(string) value := d.Get("value").(string) + variableType := stringToVariableType(d.Get("variable_type").(string)) protected := d.Get("protected").(bool) - options := gitlab.CreateVariableOptions{ - Key: &key, - Value: &value, - Protected: &protected, - EnvironmentScope: nil, + options := gitlab.CreateGroupVariableOptions{ + Key: &key, + Value: &value, + VariableType: variableType, + Protected: &protected, } log.Printf("[DEBUG] create gitlab group variable %s/%s", group, key) @@ -86,6 +93,7 @@ func resourceGitlabGroupVariableRead(d *schema.ResourceData, meta interface{}) e d.Set("key", v.Key) d.Set("value", v.Value) + d.Set("variable_type", v.VariableType) d.Set("group", group) d.Set("protected", v.Protected) return nil @@ -97,12 +105,13 @@ func resourceGitlabGroupVariableUpdate(d *schema.ResourceData, meta interface{}) group := d.Get("group").(string) key := d.Get("key").(string) value := d.Get("value").(string) + variableType := stringToVariableType(d.Get("variable_type").(string)) protected := d.Get("protected").(bool) - options := &gitlab.UpdateVariableOptions{ - Value: &value, - Protected: &protected, - EnvironmentScope: nil, + options := &gitlab.UpdateGroupVariableOptions{ + Value: &value, + Protected: &protected, + VariableType: variableType, } log.Printf("[DEBUG] update gitlab group variable %s/%s", group, key) diff --git a/gitlab/resource_gitlab_group_variable_test.go b/gitlab/resource_gitlab_group_variable_test.go index 9678a64fc..8b28d8047 100644 --- a/gitlab/resource_gitlab_group_variable_test.go +++ b/gitlab/resource_gitlab_group_variable_test.go @@ -141,6 +141,7 @@ resource "gitlab_group_variable" "foo" { group = "${gitlab_group.foo.id}" key = "key_%s" value = "value-%s" + variable_type = "file" } `, rString, rString, rString, rString) } diff --git a/gitlab/resource_gitlab_project_variable.go b/gitlab/resource_gitlab_project_variable.go index 22ac25835..8d17d6772 100644 --- a/gitlab/resource_gitlab_project_variable.go +++ b/gitlab/resource_gitlab_project_variable.go @@ -34,11 +34,27 @@ func resourceGitlabProjectVariable() *schema.Resource { Required: true, Sensitive: true, }, + "variable_type": { + Type: schema.TypeString, + Optional: true, + Default: "env_var", + ValidateFunc: StringIsGitlabVariableType(), + }, "protected": { Type: schema.TypeBool, Optional: true, Default: false, }, + "masked": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "environment_scope": { + Type: schema.TypeString, + Optional: true, + Default: false, + }, }, } } @@ -49,13 +65,18 @@ func resourceGitlabProjectVariableCreate(d *schema.ResourceData, meta interface{ project := d.Get("project").(string) key := d.Get("key").(string) value := d.Get("value").(string) + variableType := stringToVariableType(d.Get("variable_type").(string)) protected := d.Get("protected").(bool) + masked := d.Get("masked").(bool) + environmentScope := d.Get("environment_scope").(string) - options := gitlab.CreateVariableOptions{ + options := gitlab.CreateProjectVariableOptions{ Key: &key, Value: &value, + VariableType: variableType, Protected: &protected, - EnvironmentScope: nil, + Masked: &masked, + EnvironmentScope: &environmentScope, } log.Printf("[DEBUG] create gitlab project variable %s/%s", project, key) @@ -86,8 +107,14 @@ func resourceGitlabProjectVariableRead(d *schema.ResourceData, meta interface{}) d.Set("key", v.Key) d.Set("value", v.Value) + d.Set("variable_type", v.VariableType) d.Set("project", project) d.Set("protected", v.Protected) + d.Set("masked", v.Masked) + //For now I'm ignoring environment_scope when reading back data. (this can cause configuration drift so it is bad). + //However I'm unable to stop terraform from gratuitously updating this to values that are unacceptable by Gitlab) + //I don't have an enterprise license to properly test this either. + //d.Set("environment_scope", v.EnvironmentScope) return nil } @@ -97,12 +124,17 @@ func resourceGitlabProjectVariableUpdate(d *schema.ResourceData, meta interface{ project := d.Get("project").(string) key := d.Get("key").(string) value := d.Get("value").(string) + variableType := stringToVariableType(d.Get("variable_type").(string)) protected := d.Get("protected").(bool) + masked := d.Get("masked").(bool) + environmentScope := d.Get("environment_scope").(string) - options := &gitlab.UpdateVariableOptions{ + options := &gitlab.UpdateProjectVariableOptions{ Value: &value, + VariableType: variableType, Protected: &protected, - EnvironmentScope: nil, + Masked: &masked, + EnvironmentScope: &environmentScope, } log.Printf("[DEBUG] update gitlab project variable %s/%s", project, key) diff --git a/gitlab/resource_gitlab_project_variable_test.go b/gitlab/resource_gitlab_project_variable_test.go index dad2cf143..89fcfb12f 100644 --- a/gitlab/resource_gitlab_project_variable_test.go +++ b/gitlab/resource_gitlab_project_variable_test.go @@ -145,6 +145,7 @@ resource "gitlab_project_variable" "foo" { project = "${gitlab_project.foo.id}" key = "key_%s" value = "value-%s" + variable_type = "env_var" } `, rString, rString, rString) } diff --git a/gitlab/util.go b/gitlab/util.go index 445f977f7..25893de5b 100644 --- a/gitlab/util.go +++ b/gitlab/util.go @@ -91,6 +91,19 @@ func stringToVisibilityLevel(s string) *gitlab.VisibilityValue { return &value } +func stringToVariableType(s string) *gitlab.VariableTypeValue { + lookup := map[string]gitlab.VariableTypeValue{ + "env_var": gitlab.EnvVariableType, + "file": gitlab.FileVariableType, + } + + value, ok := lookup[s] + if !ok { + return nil + } + return &value +} + func stringToMergeMethod(s string) *gitlab.MergeMethodValue { lookup := map[string]gitlab.MergeMethodValue{ "merge": gitlab.NoFastForwardMerge, @@ -124,6 +137,21 @@ func StringIsGitlabVariableName() schema.SchemaValidateFunc { } } +func StringIsGitlabVariableType() schema.SchemaValidateFunc { + return func(v interface{}, k string) (s []string, es []error) { + value, ok := v.(string) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be string", k)) + return + } + variableType := stringToVariableType(value) + if variableType == nil { + es = append(es, fmt.Errorf("expected variable_type to be \"env_var\" or \"file\"")) + } + return + } +} + // return the pieces of id `a:b` as a, b func parseTwoPartID(id string) (string, string, error) { parts := strings.SplitN(id, ":", 2) diff --git a/website/docs/r/group_variable.html.markdown b/website/docs/r/group_variable.html.markdown index b23c612f6..cd3143273 100644 --- a/website/docs/r/group_variable.html.markdown +++ b/website/docs/r/group_variable.html.markdown @@ -34,6 +34,8 @@ The following arguments are supported: * `value` - (Required, string) The value of the variable. +* `variable_type` - (Optional, string) The type of a variable. Available types are: env_var (default) and file. + * `protected` - (Optional, boolean) If set to `true`, the variable will be passed only to pipelines running on protected branches and tags. Defaults to `false`. ## Import diff --git a/website/docs/r/project_variable.html.markdown b/website/docs/r/project_variable.html.markdown index ada3dfe08..dc8fade46 100644 --- a/website/docs/r/project_variable.html.markdown +++ b/website/docs/r/project_variable.html.markdown @@ -34,8 +34,14 @@ The following arguments are supported: * `value` - (Required, string) The value of the variable. +* `variable_type` - (Optional, string) The type of a variable. Available types are: env_var (default) and file. + * `protected` - (Optional, boolean) If set to `true`, the variable will be passed only to pipelines running on protected branches and tags. Defaults to `false`. +* `masked` - (Optional, boolean) If set to `true`, the variable will be masked if it would have been written to the logs. Defaults to `false`. + +* `environment_scope` - (Optional, string) The environment_scope of the variable + ## Import GitLab project variables can be imported using an id made up of `projectid:variablename`, e.g. From 25f69fa0f7c59338483c27b0ff21fda900a7c827 Mon Sep 17 00:00:00 2001 From: Wijk Date: Thu, 15 Aug 2019 15:13:16 +0200 Subject: [PATCH 2/3] Upgrade go-gitlab support from v0.18.0 to v0.20.0 --- go.mod | 2 +- go.sum | 2 + vendor/github.com/xanzy/go-gitlab/.travis.yml | 1 - vendor/github.com/xanzy/go-gitlab/README.md | 8 +- .../xanzy/go-gitlab/build_variables.go | 172 -------------- vendor/github.com/xanzy/go-gitlab/commits.go | 103 ++++++-- .../xanzy/go-gitlab/environments.go | 34 ++- vendor/github.com/xanzy/go-gitlab/gitlab.go | 19 +- .../xanzy/go-gitlab/group_variables.go | 34 ++- vendor/github.com/xanzy/go-gitlab/issues.go | 67 +++--- vendor/github.com/xanzy/go-gitlab/jobs.go | 45 ++-- .../xanzy/go-gitlab/merge_requests.go | 9 + vendor/github.com/xanzy/go-gitlab/notes.go | 3 +- .../xanzy/go-gitlab/project_import_export.go | 6 +- .../xanzy/go-gitlab/project_variables.go | 46 ++-- vendor/github.com/xanzy/go-gitlab/projects.go | 28 ++- .../xanzy/go-gitlab/protected_branches.go | 5 +- .../xanzy/go-gitlab/repositories.go | 5 +- .../xanzy/go-gitlab/resource_label_events.go | 219 ++++++++++++++++++ vendor/github.com/xanzy/go-gitlab/runners.go | 1 + vendor/github.com/xanzy/go-gitlab/settings.go | 4 +- vendor/github.com/xanzy/go-gitlab/todos.go | 1 + vendor/modules.txt | 2 +- 23 files changed, 530 insertions(+), 286 deletions(-) delete mode 100644 vendor/github.com/xanzy/go-gitlab/build_variables.go create mode 100644 vendor/github.com/xanzy/go-gitlab/resource_label_events.go diff --git a/go.mod b/go.mod index afc2d6faa..6ae7f5fd5 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/spf13/afero v1.2.2 // indirect github.com/ulikunitz/xz v0.5.6 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect - github.com/xanzy/go-gitlab v0.18.0 + github.com/xanzy/go-gitlab v0.20.0 golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect golang.org/x/oauth2 v0.0.0-20190517181255-950ef44c6e07 // indirect diff --git a/go.sum b/go.sum index 1dafe4fae..425780ef8 100644 --- a/go.sum +++ b/go.sum @@ -355,6 +355,8 @@ github.com/xanzy/go-gitlab v0.17.0 h1:+ajmfVENiehiK8FgQXb0v/XEsYPAdf9vVE53iQ2fiG github.com/xanzy/go-gitlab v0.17.0/go.mod h1:LSfUQ9OPDnwRqulJk2HcWaAiFfCzaknyeGvjQI67MbE= github.com/xanzy/go-gitlab v0.18.0 h1:LybNSWSIw8BK+GnxuETAhUXEzzh5rHsHjopqVkGJXRE= github.com/xanzy/go-gitlab v0.18.0/go.mod h1:LSfUQ9OPDnwRqulJk2HcWaAiFfCzaknyeGvjQI67MbE= +github.com/xanzy/go-gitlab v0.20.0 h1:UE8uvZ8DAOeYTTVqwqUmwnUqeUVgXYk0Mbam6FvutrQ= +github.com/xanzy/go-gitlab v0.20.0/go.mod h1:LSfUQ9OPDnwRqulJk2HcWaAiFfCzaknyeGvjQI67MbE= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= diff --git a/vendor/github.com/xanzy/go-gitlab/.travis.yml b/vendor/github.com/xanzy/go-gitlab/.travis.yml index 556aec780..0c9e88578 100644 --- a/vendor/github.com/xanzy/go-gitlab/.travis.yml +++ b/vendor/github.com/xanzy/go-gitlab/.travis.yml @@ -1,7 +1,6 @@ language: go go: - - 1.9.x - 1.10.x - 1.11.x - 1.12.x diff --git a/vendor/github.com/xanzy/go-gitlab/README.md b/vendor/github.com/xanzy/go-gitlab/README.md index 976673866..5f6321f50 100644 --- a/vendor/github.com/xanzy/go-gitlab/README.md +++ b/vendor/github.com/xanzy/go-gitlab/README.md @@ -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 diff --git a/vendor/github.com/xanzy/go-gitlab/build_variables.go b/vendor/github.com/xanzy/go-gitlab/build_variables.go deleted file mode 100644 index a34bc40ca..000000000 --- a/vendor/github.com/xanzy/go-gitlab/build_variables.go +++ /dev/null @@ -1,172 +0,0 @@ -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) -} diff --git a/vendor/github.com/xanzy/go-gitlab/commits.go b/vendor/github.com/xanzy/go-gitlab/commits.go index 7556394b6..cb03c3a09 100644 --- a/vendor/github.com/xanzy/go-gitlab/commits.go +++ b/vendor/github.com/xanzy/go-gitlab/commits.go @@ -18,6 +18,7 @@ package gitlab import ( "fmt" + "net/url" "time" ) @@ -145,19 +146,19 @@ type GetCommitRefsOptions struct { // // GitLab API docs: // https://docs.gitlab.com/ce/api/commits.html#get-references-a-commit-is-pushed-to -func (s *CommitsService) GetCommitRefs(pid interface{}, sha string, opt *GetCommitRefsOptions, options ...OptionFunc) ([]CommitRef, *Response, error) { +func (s *CommitsService) GetCommitRefs(pid interface{}, sha string, opt *GetCommitRefsOptions, options ...OptionFunc) ([]*CommitRef, *Response, error) { project, err := parseID(pid) if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/commits/%s/refs", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/commits/%s/refs", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("GET", u, opt, options) if err != nil { return nil, nil, err } - var cs []CommitRef + var cs []*CommitRef resp, err := s.client.Do(req, &cs) if err != nil { return nil, resp, err @@ -175,7 +176,7 @@ func (s *CommitsService) GetCommit(pid interface{}, sha string, options ...Optio if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/commits/%s", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/commits/%s", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("GET", u, nil, options) if err != nil { @@ -218,7 +219,7 @@ func (s *CommitsService) CreateCommit(pid interface{}, opt *CreateCommitOptions, return nil, nil, err } - var c *Commit + c := new(Commit) resp, err := s.client.Do(req, &c) if err != nil { return nil, resp, err @@ -260,7 +261,7 @@ func (s *CommitsService) GetCommitDiff(pid interface{}, sha string, opt *GetComm if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/commits/%s/diff", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/commits/%s/diff", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("GET", u, opt, options) if err != nil { @@ -317,7 +318,7 @@ func (s *CommitsService) GetCommitComments(pid interface{}, sha string, opt *Get if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/commits/%s/comments", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/commits/%s/comments", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("GET", u, opt, options) if err != nil { @@ -356,7 +357,7 @@ func (s *CommitsService) PostCommitComment(pid interface{}, sha string, opt *Pos if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/commits/%s/comments", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/commits/%s/comments", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("POST", u, opt, options) if err != nil { @@ -408,7 +409,7 @@ func (s *CommitsService) GetCommitStatuses(pid interface{}, sha string, opt *Get if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/commits/%s/statuses", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/commits/%s/statuses", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("GET", u, opt, options) if err != nil { @@ -444,14 +445,14 @@ func (s *CommitsService) SetCommitStatus(pid interface{}, sha string, opt *SetCo if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/statuses/%s", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/statuses/%s", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("POST", u, opt, options) if err != nil { return nil, nil, err } - var cs *CommitStatus + cs := new(CommitStatus) resp, err := s.client.Do(req, &cs) if err != nil { return nil, resp, err @@ -469,7 +470,7 @@ func (s *CommitsService) GetMergeRequestsByCommit(pid interface{}, sha string, o if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/commits/%s/merge_requests", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/commits/%s/merge_requests", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("GET", u, nil, options) if err != nil { @@ -485,14 +486,14 @@ func (s *CommitsService) GetMergeRequestsByCommit(pid interface{}, sha string, o return mrs, resp, err } -// CherryPickCommitOptions represents the available options for cherry-picking a commit. +// CherryPickCommitOptions represents the available CherryPickCommit() options. // // GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#cherry-pick-a-commit type CherryPickCommitOptions struct { - TargetBranch *string `url:"branch" json:"branch,omitempty"` + Branch *string `url:"branch,omitempty" json:"branch,omitempty"` } -// CherryPickCommit sherry picks a commit to a given branch. +// CherryPickCommit cherry picks a commit to a given branch. // // GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#cherry-pick-a-commit func (s *CommitsService) CherryPickCommit(pid interface{}, sha string, opt *CherryPickCommitOptions, options ...OptionFunc) (*Commit, *Response, error) { @@ -500,14 +501,45 @@ func (s *CommitsService) CherryPickCommit(pid interface{}, sha string, opt *Cher if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/commits/%s/cherry_pick", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/commits/%s/cherry_pick", pathEscape(project), url.PathEscape(sha)) + + req, err := s.client.NewRequest("POST", u, opt, options) + if err != nil { + return nil, nil, err + } + + c := new(Commit) + resp, err := s.client.Do(req, &c) + if err != nil { + return nil, resp, err + } + + return c, resp, err +} + +// RevertCommitOptions represents the available RevertCommit() options. +// +// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#revert-a-commit +type RevertCommitOptions struct { + Branch *string `url:"branch,omitempty" json:"branch,omitempty"` +} + +// RevertCommit reverts a commit in a given branch. +// +// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#revert-a-commit +func (s *CommitsService) RevertCommit(pid interface{}, sha string, opt *RevertCommitOptions, options ...OptionFunc) (*Commit, *Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/repository/commits/%s/revert", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("POST", u, opt, options) if err != nil { return nil, nil, err } - var c *Commit + c := new(Commit) resp, err := s.client.Do(req, &c) if err != nil { return nil, resp, err @@ -515,3 +547,40 @@ func (s *CommitsService) CherryPickCommit(pid interface{}, sha string, opt *Cher return c, resp, err } + +// GPGSignature represents a Gitlab commit's GPG Signature. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/commits.html#get-gpg-signature-of-a-commit +type GPGSignature struct { + KeyID int `json:"gpg_key_id"` + KeyPrimaryKeyID string `json:"gpg_key_primary_keyid"` + KeyUserName string `json:"gpg_key_user_name"` + KeyUserEmail string `json:"gpg_key_user_email"` + VerificationStatus string `json:"verification_status"` + KeySubkeyID int `json:"gpg_key_subkey_id"` +} + +// GetGPGSiganature gets a GPG signature of a commit. +// +// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#get-gpg-signature-of-a-commit +func (s *CommitsService) GetGPGSiganature(pid interface{}, sha string, options ...OptionFunc) (*GPGSignature, *Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/repository/commits/%s/signature", pathEscape(project), url.PathEscape(sha)) + + req, err := s.client.NewRequest("GET", u, nil, options) + if err != nil { + return nil, nil, err + } + + sig := new(GPGSignature) + resp, err := s.client.Do(req, &sig) + if err != nil { + return nil, resp, err + } + + return sig, resp, err +} diff --git a/vendor/github.com/xanzy/go-gitlab/environments.go b/vendor/github.com/xanzy/go-gitlab/environments.go index f7c81f09e..ee7730742 100644 --- a/vendor/github.com/xanzy/go-gitlab/environments.go +++ b/vendor/github.com/xanzy/go-gitlab/environments.go @@ -32,10 +32,11 @@ type EnvironmentsService struct { // // GitLab API docs: https://docs.gitlab.com/ce/api/environments.html type Environment struct { - ID int `json:"id"` - Name string `json:"name"` - Slug string `json:"slug"` - ExternalURL string `json:"external_url"` + ID int `json:"id"` + Name string `json:"name"` + Slug string `json:"slug"` + ExternalURL string `json:"external_url"` + LastDeployment *Deployment `json:"last_deployment"` } func (env Environment) String() string { @@ -74,6 +75,31 @@ func (s *EnvironmentsService) ListEnvironments(pid interface{}, opts *ListEnviro return envs, resp, err } +// GetEnvironment gets a specific environment from a project. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/environments.html#get-a-specific-environment +func (s *EnvironmentsService) GetEnvironment(pid interface{}, environment int, options ...OptionFunc) (*Environment, *Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/environments/%d", pathEscape(project), environment) + + req, err := s.client.NewRequest("GET", u, nil, options) + if err != nil { + return nil, nil, err + } + + env := new(Environment) + resp, err := s.client.Do(req, env) + if err != nil { + return nil, resp, err + } + + return env, resp, err +} + // CreateEnvironmentOptions represents the available CreateEnvironment() options. // // GitLab API docs: diff --git a/vendor/github.com/xanzy/go-gitlab/gitlab.go b/vendor/github.com/xanzy/go-gitlab/gitlab.go index 8734af09a..dd015b4a9 100644 --- a/vendor/github.com/xanzy/go-gitlab/gitlab.go +++ b/vendor/github.com/xanzy/go-gitlab/gitlab.go @@ -204,7 +204,7 @@ var notificationLevelTypes = map[string]NotificationLevelValue{ // GitLab API docs: https://docs.gitlab.com/ce/api/ type VisibilityValue string -// List of available visibility levels +// List of available visibility levels. // // GitLab API docs: https://docs.gitlab.com/ce/api/ const ( @@ -213,6 +213,19 @@ const ( PublicVisibility VisibilityValue = "public" ) +// VariableTypeValue represents a variable type within GitLab. +// +// GitLab API docs: https://docs.gitlab.com/ce/api/ +type VariableTypeValue string + +// List of available variable types. +// +// GitLab API docs: https://docs.gitlab.com/ce/api/ +const ( + EnvVariableType VariableTypeValue = "env_var" + FileVariableType VariableTypeValue = "file" +) + // MergeMethodValue represents a project merge type within GitLab. // // GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#project-merge-method @@ -291,7 +304,6 @@ type Client struct { Boards *IssueBoardsService Branches *BranchesService BroadcastMessage *BroadcastMessagesService - BuildVariables *BuildVariablesService CIYMLTemplate *CIYMLTemplatesService Commits *CommitsService ContainerRegistry *ContainerRegistryService @@ -341,6 +353,7 @@ type Client struct { Releases *ReleasesService Repositories *RepositoriesService RepositoryFiles *RepositoryFilesService + ResourceLabelEvents *ResourceLabelEventsService Runners *RunnersService Search *SearchService Services *ServicesService @@ -440,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} @@ -490,6 +502,7 @@ func newClient(httpClient *http.Client) *Client { c.Releases = &ReleasesService{client: c} c.Repositories = &RepositoriesService{client: c} c.RepositoryFiles = &RepositoryFilesService{client: c} + c.ResourceLabelEvents = &ResourceLabelEventsService{client: c} c.Runners = &RunnersService{client: c} c.Search = &SearchService{client: c} c.Services = &ServicesService{client: c} diff --git a/vendor/github.com/xanzy/go-gitlab/group_variables.go b/vendor/github.com/xanzy/go-gitlab/group_variables.go index c91629aeb..942618b25 100644 --- a/vendor/github.com/xanzy/go-gitlab/group_variables.go +++ b/vendor/github.com/xanzy/go-gitlab/group_variables.go @@ -35,9 +35,10 @@ type GroupVariablesService struct { // GitLab API docs: // https://docs.gitlab.com/ee/api/group_level_variables.html type GroupVariable struct { - Key string `json:"key"` - Value string `json:"value"` - Protected bool `json:"protected"` + Key string `json:"key"` + Value string `json:"value"` + VariableType VariableTypeValue `json:"variable_type"` + Protected bool `json:"protected"` } func (v GroupVariable) String() string { @@ -94,11 +95,23 @@ func (s *GroupVariablesService) GetVariable(gid interface{}, key string, options return v, resp, err } +// CreateGroupVariableOptions represents the available CreateVariable() +// options. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/group_level_variables.html#create-variable +type CreateGroupVariableOptions struct { + Key *string `url:"key,omitempty" json:"key,omitempty"` + Value *string `url:"value,omitempty" json:"value,omitempty"` + VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` + Protected *bool `url:"protected,omitempty" json:"protected,omitempty"` +} + // CreateVariable creates a new group variable. // // GitLab API docs: // https://docs.gitlab.com/ee/api/group_level_variables.html#create-variable -func (s *GroupVariablesService) CreateVariable(gid interface{}, opt *CreateVariableOptions, options ...OptionFunc) (*GroupVariable, *Response, error) { +func (s *GroupVariablesService) CreateVariable(gid interface{}, opt *CreateGroupVariableOptions, options ...OptionFunc) (*GroupVariable, *Response, error) { group, err := parseID(gid) if err != nil { return nil, nil, err @@ -119,12 +132,23 @@ func (s *GroupVariablesService) CreateVariable(gid interface{}, opt *CreateVaria return v, resp, err } +// UpdateGroupVariableOptions represents the available UpdateVariable() +// options. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/group_level_variables.html#update-variable +type UpdateGroupVariableOptions struct { + Value *string `url:"value,omitempty" json:"value,omitempty"` + VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` + Protected *bool `url:"protected,omitempty" json:"protected,omitempty"` +} + // UpdateVariable updates the position of an existing // group issue board list. // // GitLab API docs: // https://docs.gitlab.com/ee/api/group_level_variables.html#update-variable -func (s *GroupVariablesService) UpdateVariable(gid interface{}, key string, opt *UpdateVariableOptions, options ...OptionFunc) (*GroupVariable, *Response, error) { +func (s *GroupVariablesService) UpdateVariable(gid interface{}, key string, opt *UpdateGroupVariableOptions, options ...OptionFunc) (*GroupVariable, *Response, error) { group, err := parseID(gid) if err != nil { return nil, nil, err diff --git a/vendor/github.com/xanzy/go-gitlab/issues.go b/vendor/github.com/xanzy/go-gitlab/issues.go index 2f031a755..ed9c2bf08 100644 --- a/vendor/github.com/xanzy/go-gitlab/issues.go +++ b/vendor/github.com/xanzy/go-gitlab/issues.go @@ -110,21 +110,23 @@ func (l *Labels) MarshalJSON() ([]byte, error) { // GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-issues type ListIssuesOptions struct { ListOptions - State *string `url:"state,omitempty" json:"state,omitempty"` - Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"` - Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"` - Scope *string `url:"scope,omitempty" json:"scope,omitempty"` - AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"` - AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"` - MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"` - IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"` - OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"` - Sort *string `url:"sort,omitempty" json:"sort,omitempty"` - Search *string `url:"search,omitempty" json:"search,omitempty"` - CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"` - CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"` - UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"` - UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"` + State *string `url:"state,omitempty" json:"state,omitempty"` + Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"` + WithLabelDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"` + Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"` + Scope *string `url:"scope,omitempty" json:"scope,omitempty"` + AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"` + AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"` + MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"` + IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"` + OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"` + Sort *string `url:"sort,omitempty" json:"sort,omitempty"` + Search *string `url:"search,omitempty" json:"search,omitempty"` + CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"` + CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"` + UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"` + UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"` + Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` } // ListIssues gets all issues created by authenticated user. This function @@ -162,6 +164,7 @@ type ListGroupIssuesOptions struct { OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"` Sort *string `url:"sort,omitempty" json:"sort,omitempty"` Search *string `url:"search,omitempty" json:"search,omitempty"` + In *string `url:"in,omitempty" json:"in,omitempty"` CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"` CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"` UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"` @@ -198,21 +201,24 @@ func (s *IssuesService) ListGroupIssues(pid interface{}, opt *ListGroupIssuesOpt // GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-project-issues type ListProjectIssuesOptions struct { ListOptions - IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"` - State *string `url:"state,omitempty" json:"state,omitempty"` - Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"` - Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"` - Scope *string `url:"scope,omitempty" json:"scope,omitempty"` - AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"` - AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"` - MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"` - OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"` - Sort *string `url:"sort,omitempty" json:"sort,omitempty"` - Search *string `url:"search,omitempty" json:"search,omitempty"` - CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"` - CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"` - UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"` - UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"` + IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"` + State *string `url:"state,omitempty" json:"state,omitempty"` + Labels Labels `url:"labels,comma,omitempty" json:"labels,omitempty"` + WithLabelDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"` + Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"` + Scope *string `url:"scope,omitempty" json:"scope,omitempty"` + AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"` + AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"` + MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"` + OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"` + Sort *string `url:"sort,omitempty" json:"sort,omitempty"` + Search *string `url:"search,omitempty" json:"search,omitempty"` + In *string `url:"in,omitempty" json:"in,omitempty"` + CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"` + CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"` + UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"` + UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"` + Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` } // ListProjectIssues gets a list of project issues. This function accepts @@ -268,6 +274,7 @@ func (s *IssuesService) GetIssue(pid interface{}, issue int, options ...OptionFu // // GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#new-issues type CreateIssueOptions struct { + IID *int `url:"iid,omitempty" json:"iid,omitempty"` Title *string `url:"title,omitempty" json:"title,omitempty"` Description *string `url:"description,omitempty" json:"description,omitempty"` Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"` diff --git a/vendor/github.com/xanzy/go-gitlab/jobs.go b/vendor/github.com/xanzy/go-gitlab/jobs.go index daced463b..f0c1e2c46 100644 --- a/vendor/github.com/xanzy/go-gitlab/jobs.go +++ b/vendor/github.com/xanzy/go-gitlab/jobs.go @@ -35,23 +35,33 @@ type JobsService struct { // // GitLab API docs: https://docs.gitlab.com/ce/api/jobs.html type Job struct { - Commit *Commit `json:"commit"` - CreatedAt *time.Time `json:"created_at"` - Coverage float64 `json:"coverage"` - ArtifactsFile struct { - Filename string `json:"filename"` - Size int `json:"size"` - } `json:"artifacts_file"` - FinishedAt *time.Time `json:"finished_at"` - ID int `json:"id"` - Name string `json:"name"` - Pipeline struct { + Commit *Commit `json:"commit"` + Coverage float64 `json:"coverage"` + AllowFailure bool `json:"allow_failure"` + CreatedAt *time.Time `json:"created_at"` + StartedAt *time.Time `json:"started_at"` + FinishedAt *time.Time `json:"finished_at"` + Duration float64 `json:"duration"` + ArtifactsExpireAt *time.Time `json:"artifacts_expire_at"` + ID int `json:"id"` + Name string `json:"name"` + Pipeline struct { ID int `json:"id"` Ref string `json:"ref"` Sha string `json:"sha"` Status string `json:"status"` } `json:"pipeline"` - Ref string `json:"ref"` + Ref string `json:"ref"` + Artifacts []struct { + FileType string `json:"file_type"` + Filename string `json:"filename"` + Size int `json:"size"` + FileFormat string `json:"file_format"` + } `json:"artifacts"` + ArtifactsFile struct { + Filename string `json:"filename"` + Size int `json:"size"` + } `json:"artifacts_file"` Runner struct { ID int `json:"id"` Description string `json:"description"` @@ -59,12 +69,11 @@ type Job struct { IsShared bool `json:"is_shared"` Name string `json:"name"` } `json:"runner"` - Stage string `json:"stage"` - StartedAt *time.Time `json:"started_at"` - Status string `json:"status"` - Tag bool `json:"tag"` - User *User `json:"user"` - WebURL string `json:"web_url"` + Stage string `json:"stage"` + Status string `json:"status"` + Tag bool `json:"tag"` + WebURL string `json:"web_url"` + User *User `json:"user"` } // ListJobsOptions are options for two list apis diff --git a/vendor/github.com/xanzy/go-gitlab/merge_requests.go b/vendor/github.com/xanzy/go-gitlab/merge_requests.go index c1f4268aa..0626db1f7 100644 --- a/vendor/github.com/xanzy/go-gitlab/merge_requests.go +++ b/vendor/github.com/xanzy/go-gitlab/merge_requests.go @@ -51,6 +51,8 @@ type MergeRequest struct { Name string `json:"name"` State string `json:"state"` CreatedAt *time.Time `json:"created_at"` + AvatarURL string `json:"avatar_url"` + WebURL string `json:"web_url"` } `json:"author"` Assignee struct { ID int `json:"id"` @@ -58,6 +60,8 @@ type MergeRequest struct { Name string `json:"name"` State string `json:"state"` CreatedAt *time.Time `json:"created_at"` + AvatarURL string `json:"avatar_url"` + WebURL string `json:"web_url"` } `json:"assignee"` SourceProjectID int `json:"source_project_id"` TargetProjectID int `json:"target_project_id"` @@ -67,12 +71,15 @@ type MergeRequest struct { Milestone *Milestone `json:"milestone"` MergeWhenPipelineSucceeds bool `json:"merge_when_pipeline_succeeds"` MergeStatus string `json:"merge_status"` + MergeError string `json:"merge_error"` MergedBy struct { ID int `json:"id"` Username string `json:"username"` Name string `json:"name"` State string `json:"state"` CreatedAt *time.Time `json:"created_at"` + AvatarURL string `json:"avatar_url"` + WebURL string `json:"web_url"` } `json:"merged_by"` MergedAt *time.Time `json:"merged_at"` ClosedBy struct { @@ -81,6 +88,8 @@ type MergeRequest struct { Name string `json:"name"` State string `json:"state"` CreatedAt *time.Time `json:"created_at"` + AvatarURL string `json:"avatar_url"` + WebURL string `json:"web_url"` } `json:"closed_by"` ClosedAt *time.Time `json:"closed_at"` Subscribed bool `json:"subscribed"` diff --git a/vendor/github.com/xanzy/go-gitlab/notes.go b/vendor/github.com/xanzy/go-gitlab/notes.go index 272646028..91ecf450e 100644 --- a/vendor/github.com/xanzy/go-gitlab/notes.go +++ b/vendor/github.com/xanzy/go-gitlab/notes.go @@ -154,7 +154,8 @@ func (s *NotesService) GetIssueNote(pid interface{}, issue, note int, options .. // GitLab API docs: // https://docs.gitlab.com/ce/api/notes.html#create-new-issue-note type CreateIssueNoteOptions struct { - Body *string `url:"body,omitempty" json:"body,omitempty"` + Body *string `url:"body,omitempty" json:"body,omitempty"` + CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"` } // CreateIssueNote creates a new note to a single project issue. diff --git a/vendor/github.com/xanzy/go-gitlab/project_import_export.go b/vendor/github.com/xanzy/go-gitlab/project_import_export.go index a71d620bc..839b187b5 100644 --- a/vendor/github.com/xanzy/go-gitlab/project_import_export.go +++ b/vendor/github.com/xanzy/go-gitlab/project_import_export.go @@ -151,12 +151,12 @@ type ImportFileOptions struct { OverrideParams *CreateProjectOptions `url:"override_params,omitempty" json:"override_params,omitempty"` } -// ImportProject import the project. +// ImportFile import a file. // // GitLab API docs: // https://docs.gitlab.com/ce/api/project_import_export.html#import-a-file -func (s *ProjectImportExportService) ImportProject(opt *ImportFileOptions, options ...OptionFunc) (*ImportStatus, *Response, error) { - req, err := s.client.NewRequest("POST", "/projects/import", opt, options) +func (s *ProjectImportExportService) ImportFile(opt *ImportFileOptions, options ...OptionFunc) (*ImportStatus, *Response, error) { + req, err := s.client.NewRequest("POST", "projects/import", opt, options) if err != nil { return nil, nil, err } diff --git a/vendor/github.com/xanzy/go-gitlab/project_variables.go b/vendor/github.com/xanzy/go-gitlab/project_variables.go index 9be68e668..2068f9ebb 100644 --- a/vendor/github.com/xanzy/go-gitlab/project_variables.go +++ b/vendor/github.com/xanzy/go-gitlab/project_variables.go @@ -35,10 +35,12 @@ type ProjectVariablesService struct { // GitLab API docs: // https://docs.gitlab.com/ee/api/project_level_variables.html type ProjectVariable struct { - Key string `json:"key"` - Value string `json:"value"` - Protected bool `json:"protected"` - EnvironmentScope string `json:"environment_scope"` + Key string `json:"key"` + Value string `json:"value"` + VariableType VariableTypeValue `json:"variable_type"` + Protected bool `json:"protected"` + Masked bool `json:"masked"` + EnvironmentScope string `json:"environment_scope"` } func (v ProjectVariable) String() string { @@ -95,23 +97,25 @@ func (s *ProjectVariablesService) GetVariable(pid interface{}, key string, optio return v, resp, err } -// CreateVariableOptions represents the available -// CreateVariable() options. +// CreateProjectVariableOptions represents the available CreateVariable() +// options. // // GitLab API docs: // https://docs.gitlab.com/ee/api/project_level_variables.html#create-variable -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"` +type CreateProjectVariableOptions struct { + Key *string `url:"key,omitempty" json:"key,omitempty"` + Value *string `url:"value,omitempty" json:"value,omitempty"` + VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` + Protected *bool `url:"protected,omitempty" json:"protected,omitempty"` + Masked *bool `url:"masked,omitempty" json:"masked,omitempty"` + EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"` } // CreateVariable creates a new project variable. // // GitLab API docs: // https://docs.gitlab.com/ee/api/project_level_variables.html#create-variable -func (s *ProjectVariablesService) CreateVariable(pid interface{}, opt *CreateVariableOptions, options ...OptionFunc) (*ProjectVariable, *Response, error) { +func (s *ProjectVariablesService) CreateVariable(pid interface{}, opt *CreateProjectVariableOptions, options ...OptionFunc) (*ProjectVariable, *Response, error) { project, err := parseID(pid) if err != nil { return nil, nil, err @@ -132,22 +136,24 @@ func (s *ProjectVariablesService) CreateVariable(pid interface{}, opt *CreateVar return v, resp, err } -// UpdateVariableOptions represents the available -// UpdateVariable() options. +// UpdateProjectVariableOptions represents the available UpdateVariable() +// options. // // GitLab API docs: // https://docs.gitlab.com/ee/api/project_level_variables.html#update-variable -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"` +type UpdateProjectVariableOptions struct { + Value *string `url:"value,omitempty" json:"value,omitempty"` + VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"` + Protected *bool `url:"protected,omitempty" json:"protected,omitempty"` + Masked *bool `url:"masked,omitempty" json:"masked,omitempty"` + EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"` } -// UpdateVariable updates a project's variable +// UpdateVariable updates a project's variable. // // GitLab API docs: // https://docs.gitlab.com/ee/api/project_level_variables.html#update-variable -func (s *ProjectVariablesService) UpdateVariable(pid interface{}, key string, opt *UpdateVariableOptions, options ...OptionFunc) (*ProjectVariable, *Response, error) { +func (s *ProjectVariablesService) UpdateVariable(pid interface{}, key string, opt *UpdateProjectVariableOptions, options ...OptionFunc) (*ProjectVariable, *Response, error) { project, err := parseID(pid) if err != nil { return nil, nil, err diff --git a/vendor/github.com/xanzy/go-gitlab/projects.go b/vendor/github.com/xanzy/go-gitlab/projects.go index 8bd4f3fcc..b6c513fac 100644 --- a/vendor/github.com/xanzy/go-gitlab/projects.go +++ b/vendor/github.com/xanzy/go-gitlab/projects.go @@ -416,7 +416,7 @@ func (s *ProjectsService) GetProjectEvents(pid interface{}, opt *GetProjectEvent return p, resp, err } -// CreateProjectOptions represents the available CreateProjects() options. +// CreateProjectOptions represents the available CreateProject() options. // // GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#create-project type CreateProjectOptions struct { @@ -1243,6 +1243,7 @@ type ProjectApprovals struct { ApprovalsBeforeMerge int `json:"approvals_before_merge"` ResetApprovalsOnPush bool `json:"reset_approvals_on_push"` DisableOverridingApproversPerMergeRequest bool `json:"disable_overriding_approvers_per_merge_request"` + MergeRequestsAuthorApproval bool `json:"merge_requests_author_approval"` } // GetApprovalConfiguration get the approval configuration for a project. @@ -1279,6 +1280,7 @@ type ChangeApprovalConfigurationOptions struct { ApprovalsBeforeMerge *int `url:"approvals_before_merge,omitempty" json:"approvals_before_merge,omitempty"` ResetApprovalsOnPush *bool `url:"reset_approvals_on_push,omitempty" json:"reset_approvals_on_push,omitempty"` DisableOverridingApproversPerMergeRequest *bool `url:"disable_overriding_approvers_per_merge_request,omitempty" json:"disable_overriding_approvers_per_merge_request,omitempty"` + MergeRequestsAuthorApproval *bool `url:"merge_requests_author_approval,omitempty" json:"merge_requests_author_approval,omitempty"` } // ChangeApprovalConfiguration updates the approval configuration for a project. @@ -1340,3 +1342,27 @@ func (s *ProjectsService) ChangeAllowedApprovers(pid interface{}, opt *ChangeAll return pa, resp, err } + +// StartMirroringProject start the pull mirroring process for a project. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/projects.html#start-the-pull-mirroring-process-for-a-project-starter +func (s *ProjectsService) StartMirroringProject(pid interface{}, options ...OptionFunc) (*Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, err + } + u := fmt.Sprintf("projects/%s/mirror/pull", pathEscape(project)) + + req, err := s.client.NewRequest("POST", u, nil, options) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req, nil) + if err != nil { + return resp, err + } + + return resp, err +} diff --git a/vendor/github.com/xanzy/go-gitlab/protected_branches.go b/vendor/github.com/xanzy/go-gitlab/protected_branches.go index 4950ecc2c..3567f6ebd 100644 --- a/vendor/github.com/xanzy/go-gitlab/protected_branches.go +++ b/vendor/github.com/xanzy/go-gitlab/protected_branches.go @@ -18,6 +18,7 @@ package gitlab import ( "fmt" + "net/url" ) // ProtectedBranchesService handles communication with the protected branch @@ -90,7 +91,7 @@ func (s *ProtectedBranchesService) GetProtectedBranch(pid interface{}, branch st if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/protected_branches/%s", pathEscape(project), branch) + u := fmt.Sprintf("projects/%s/protected_branches/%s", pathEscape(project), url.PathEscape(branch)) req, err := s.client.NewRequest("GET", u, nil, options) if err != nil { @@ -153,7 +154,7 @@ func (s *ProtectedBranchesService) UnprotectRepositoryBranches(pid interface{}, if err != nil { return nil, err } - u := fmt.Sprintf("projects/%s/protected_branches/%s", pathEscape(project), branch) + u := fmt.Sprintf("projects/%s/protected_branches/%s", pathEscape(project), url.PathEscape(branch)) req, err := s.client.NewRequest("DELETE", u, nil, options) if err != nil { diff --git a/vendor/github.com/xanzy/go-gitlab/repositories.go b/vendor/github.com/xanzy/go-gitlab/repositories.go index 75f1b854a..96766aea7 100644 --- a/vendor/github.com/xanzy/go-gitlab/repositories.go +++ b/vendor/github.com/xanzy/go-gitlab/repositories.go @@ -20,6 +20,7 @@ import ( "bytes" "fmt" "io" + "net/url" ) // RepositoriesService handles communication with the repositories related @@ -91,7 +92,7 @@ func (s *RepositoriesService) Blob(pid interface{}, sha string, options ...Optio if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/blobs/%s", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/blobs/%s", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("GET", u, nil, options) if err != nil { @@ -116,7 +117,7 @@ func (s *RepositoriesService) RawBlobContent(pid interface{}, sha string, option if err != nil { return nil, nil, err } - u := fmt.Sprintf("projects/%s/repository/blobs/%s/raw", pathEscape(project), sha) + u := fmt.Sprintf("projects/%s/repository/blobs/%s/raw", pathEscape(project), url.PathEscape(sha)) req, err := s.client.NewRequest("GET", u, nil, options) if err != nil { diff --git a/vendor/github.com/xanzy/go-gitlab/resource_label_events.go b/vendor/github.com/xanzy/go-gitlab/resource_label_events.go new file mode 100644 index 000000000..e9ff66a34 --- /dev/null +++ b/vendor/github.com/xanzy/go-gitlab/resource_label_events.go @@ -0,0 +1,219 @@ +// +// Copyright 2017, Sander van Harmelen +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package gitlab + +import ( + "fmt" + "time" +) + +// ResourceLabelEventsService handles communication with the event related +// methods of the GitLab API. +// +// GitLab API docs: https://docs.gitlab.com/ee/api/resource_label_events.html +type ResourceLabelEventsService struct { + client *Client +} + +// LabelEvent represents a resource label event. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/resource_label_events.html#get-single-issue-label-event +type LabelEvent struct { + ID int `json:"id"` + Action string `json:"action"` + CreatedAt *time.Time `json:"created_at"` + ResourceType string `json:"resource_type"` + ResourceID int `json:"resource_id"` + User struct { + ID int `json:"id"` + Name string `json:"name"` + Username string `json:"username"` + State string `json:"state"` + AvatarURL string `json:"avatar_url"` + WebURL string `json:"web_url"` + } `json:"user"` + Label struct { + ID int `json:"id"` + Name string `json:"name"` + Color string `json:"color"` + TextColor string `json:"text_color"` + Description string `json:"description"` + } `json:"label"` +} + +// ListLabelEventsOptions represents the options for all resource label events +// list methods. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/resource_label_events.html#list-project-issue-label-events +type ListLabelEventsOptions struct { + ListOptions +} + +// ListIssueLabelEvents retrieves resource label events for the +// specified project and issue. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/resource_label_events.html#list-project-issue-label-events +func (s *ResourceLabelEventsService) ListIssueLabelEvents(pid interface{}, issue int, opt *ListLabelEventsOptions, options ...OptionFunc) ([]*LabelEvent, *Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/issues/%d/resource_label_events", pathEscape(project), issue) + + req, err := s.client.NewRequest("GET", u, opt, options) + if err != nil { + return nil, nil, err + } + + var ls []*LabelEvent + resp, err := s.client.Do(req, &ls) + if err != nil { + return nil, resp, err + } + + return ls, resp, err +} + +// GetIssueLabelEvent gets a single issue-label-event. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/resource_label_events.html#get-single-issue-label-event +func (s *ResourceLabelEventsService) GetIssueLabelEvent(pid interface{}, issue int, event int, options ...OptionFunc) (*LabelEvent, *Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/issues/%d/resource_label_events/%d", pathEscape(project), issue, event) + + req, err := s.client.NewRequest("GET", u, nil, options) + if err != nil { + return nil, nil, err + } + + l := new(LabelEvent) + resp, err := s.client.Do(req, l) + if err != nil { + return nil, resp, err + } + + return l, resp, err +} + +// ListGroupEpicLabelEvents retrieves resource label events for the specified +// group and epic. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/resource_label_events.html#list-group-epic-label-events +func (s *ResourceLabelEventsService) ListGroupEpicLabelEvents(gid interface{}, epic int, opt *ListLabelEventsOptions, options ...OptionFunc) ([]*LabelEvent, *Response, error) { + group, err := parseID(gid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("groups/%s/epics/%d/resource_label_events", pathEscape(group), epic) + + req, err := s.client.NewRequest("GET", u, opt, options) + if err != nil { + return nil, nil, err + } + + var ls []*LabelEvent + resp, err := s.client.Do(req, &ls) + if err != nil { + return nil, resp, err + } + + return ls, resp, err +} + +// GetGroupEpicLabelEvent gets a single group epic label event. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/resource_label_events.html#get-single-epic-label-event +func (s *ResourceLabelEventsService) GetGroupEpicLabelEvent(gid interface{}, epic int, event int, options ...OptionFunc) (*LabelEvent, *Response, error) { + group, err := parseID(gid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("groups/%s/epics/%d/resource_label_events/%d", pathEscape(group), epic, event) + + req, err := s.client.NewRequest("GET", u, nil, options) + if err != nil { + return nil, nil, err + } + + l := new(LabelEvent) + resp, err := s.client.Do(req, l) + if err != nil { + return nil, resp, err + } + + return l, resp, err +} + +// ListMergeLabelEvents retrieves resource label events for the specified +// project and merge request. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/resource_label_events.html#list-project-merge-request-label-events +func (s *ResourceLabelEventsService) ListMergeLabelEvents(pid interface{}, request int, opt *ListLabelEventsOptions, options ...OptionFunc) ([]*LabelEvent, *Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/merge_requests/%d/resource_label_events", pathEscape(project), request) + + req, err := s.client.NewRequest("GET", u, opt, options) + if err != nil { + return nil, nil, err + } + + var ls []*LabelEvent + resp, err := s.client.Do(req, &ls) + if err != nil { + return nil, resp, err + } + + return ls, resp, err +} + +// GetMergeRequestLabelEvent gets a single merge request label event. +// +// GitLab API docs: +// https://docs.gitlab.com/ee/api/resource_label_events.html#get-single-merge-request-label-event +func (s *ResourceLabelEventsService) GetMergeRequestLabelEvent(pid interface{}, request int, event int, options ...OptionFunc) (*LabelEvent, *Response, error) { + project, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/merge_requests/%d/resource_label_events/%d", pathEscape(project), request, event) + + req, err := s.client.NewRequest("GET", u, nil, options) + if err != nil { + return nil, nil, err + } + + l := new(LabelEvent) + resp, err := s.client.Do(req, l) + if err != nil { + return nil, resp, err + } + + return l, resp, err +} diff --git a/vendor/github.com/xanzy/go-gitlab/runners.go b/vendor/github.com/xanzy/go-gitlab/runners.go index 6b1b65842..365b6124a 100644 --- a/vendor/github.com/xanzy/go-gitlab/runners.go +++ b/vendor/github.com/xanzy/go-gitlab/runners.go @@ -52,6 +52,7 @@ type RunnerDetails struct { Architecture string `json:"architecture"` Description string `json:"description"` ID int `json:"id"` + IPAddress string `json:"ip_address"` IsShared bool `json:"is_shared"` ContactedAt *time.Time `json:"contacted_at"` Name string `json:"name"` diff --git a/vendor/github.com/xanzy/go-gitlab/settings.go b/vendor/github.com/xanzy/go-gitlab/settings.go index fde9910f2..2bbc0874c 100644 --- a/vendor/github.com/xanzy/go-gitlab/settings.go +++ b/vendor/github.com/xanzy/go-gitlab/settings.go @@ -75,6 +75,7 @@ type Settings struct { ImportSources []string `json:"import_sources"` KodingEnabled bool `json:"koding_enabled"` KodingURL string `json:"koding_url"` + LocalMarkdownVersion int `json:"local_markdown_version"` MaxArtifactsSize int `json:"max_artifacts_size"` MaxAttachmentSize int `json:"max_attachment_size"` MaxPagesSize int `json:"max_pages_size"` @@ -92,7 +93,7 @@ type Settings struct { PerformanceBarEnabled bool `json:"performance_bar_enabled"` PlantumlEnabled bool `json:"plantuml_enabled"` PlantumlURL string `json:"plantuml_url"` - PollingIntervalMultiplier float64 `json:"polling_interval_multiplier"` + PollingIntervalMultiplier float64 `json:"polling_interval_multiplier,string"` ProjectExportEnabled bool `json:"project_export_enabled"` PrometheusMetricsEnabled bool `json:"prometheus_metrics_enabled"` RecaptchaEnabled bool `json:"recaptcha_enabled"` @@ -195,6 +196,7 @@ type UpdateSettingsOptions struct { ImportSources []string `url:"import_sources,omitempty" json:"import_sources,omitempty"` KodingEnabled *bool `url:"koding_enabled,omitempty" json:"koding_enabled,omitempty"` KodingURL *string `url:"koding_url,omitempty" json:"koding_url,omitempty"` + LocalMarkdownVersion *int `url:"local_markdown_version,omitempty" json:"local_markdown_version,omitempty"` MaxArtifactsSize *int `url:"max_artifacts_size,omitempty" json:"max_artifacts_size,omitempty"` MaxAttachmentSize *int `url:"max_attachment_size,omitempty" json:"max_attachment_size,omitempty"` MaxPagesSize *int `url:"max_pages_size,omitempty" json:"max_pages_size,omitempty"` diff --git a/vendor/github.com/xanzy/go-gitlab/todos.go b/vendor/github.com/xanzy/go-gitlab/todos.go index 812181d40..4c32d0858 100644 --- a/vendor/github.com/xanzy/go-gitlab/todos.go +++ b/vendor/github.com/xanzy/go-gitlab/todos.go @@ -121,6 +121,7 @@ func (t Todo) String() string { // // GitLab API docs: https://docs.gitlab.com/ce/api/todos.html#get-a-list-of-todos type ListTodosOptions struct { + ListOptions Action *TodoAction `url:"action,omitempty" json:"action,omitempty"` AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"` ProjectID *int `url:"project_id,omitempty" json:"project_id,omitempty"` diff --git a/vendor/modules.txt b/vendor/modules.txt index 29f06767f..1c374609b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -222,7 +222,7 @@ github.com/ulikunitz/xz/internal/hash # github.com/vmihailenco/msgpack v4.0.4+incompatible github.com/vmihailenco/msgpack github.com/vmihailenco/msgpack/codes -# github.com/xanzy/go-gitlab v0.18.0 +# github.com/xanzy/go-gitlab v0.20.0 github.com/xanzy/go-gitlab # github.com/zclconf/go-cty v0.0.0-20190516203816-4fecf87372ec github.com/zclconf/go-cty/cty From 03b40d12c779f5629abb6326b3a8808593c9775f Mon Sep 17 00:00:00 2001 From: wijk Date: Fri, 27 Sep 2019 22:46:09 +0200 Subject: [PATCH 3/3] Expose validation functions directly --- gitlab/resource_gitlab_group_membership.go | 2 +- gitlab/resource_gitlab_group_variable.go | 4 +- gitlab/resource_gitlab_project_variable.go | 4 +- gitlab/resource_gitlab_service_jira.go | 2 +- gitlab/util.go | 80 ++++++++++------------ gitlab/util_test.go | 4 +- 6 files changed, 43 insertions(+), 53 deletions(-) diff --git a/gitlab/resource_gitlab_group_membership.go b/gitlab/resource_gitlab_group_membership.go index bfd51ee08..214f80b62 100644 --- a/gitlab/resource_gitlab_group_membership.go +++ b/gitlab/resource_gitlab_group_membership.go @@ -41,7 +41,7 @@ func resourceGitlabGroupMembership() *schema.Resource { }, "expires_at": { Type: schema.TypeString, // Format YYYY-MM-DD - ValidateFunc: validateDateFunc(), + ValidateFunc: validateDateFunc, Optional: true, }, }, diff --git a/gitlab/resource_gitlab_group_variable.go b/gitlab/resource_gitlab_group_variable.go index cee351a30..a9c74d5bf 100644 --- a/gitlab/resource_gitlab_group_variable.go +++ b/gitlab/resource_gitlab_group_variable.go @@ -27,7 +27,7 @@ func resourceGitlabGroupVariable() *schema.Resource { Type: schema.TypeString, ForceNew: true, Required: true, - ValidateFunc: StringIsGitlabVariableName(), + ValidateFunc: StringIsGitlabVariableName, }, "value": { Type: schema.TypeString, @@ -38,7 +38,7 @@ func resourceGitlabGroupVariable() *schema.Resource { Type: schema.TypeString, Optional: true, Default: "env_var", - ValidateFunc: StringIsGitlabVariableType(), + ValidateFunc: StringIsGitlabVariableType, }, "protected": { Type: schema.TypeBool, diff --git a/gitlab/resource_gitlab_project_variable.go b/gitlab/resource_gitlab_project_variable.go index 8d17d6772..87eb9df63 100644 --- a/gitlab/resource_gitlab_project_variable.go +++ b/gitlab/resource_gitlab_project_variable.go @@ -27,7 +27,7 @@ func resourceGitlabProjectVariable() *schema.Resource { Type: schema.TypeString, ForceNew: true, Required: true, - ValidateFunc: StringIsGitlabVariableName(), + ValidateFunc: StringIsGitlabVariableName, }, "value": { Type: schema.TypeString, @@ -38,7 +38,7 @@ func resourceGitlabProjectVariable() *schema.Resource { Type: schema.TypeString, Optional: true, Default: "env_var", - ValidateFunc: StringIsGitlabVariableType(), + ValidateFunc: StringIsGitlabVariableType, }, "protected": { Type: schema.TypeBool, diff --git a/gitlab/resource_gitlab_service_jira.go b/gitlab/resource_gitlab_service_jira.go index a8c88b961..b2b359f8f 100644 --- a/gitlab/resource_gitlab_service_jira.go +++ b/gitlab/resource_gitlab_service_jira.go @@ -43,7 +43,7 @@ func resourceGitlabServiceJira() *schema.Resource { "url": { Type: schema.TypeString, Required: true, - ValidateFunc: validateURLFunc(), + ValidateFunc: validateURLFunc, }, "project_key": { Type: schema.TypeString, diff --git a/gitlab/util.go b/gitlab/util.go index 25893de5b..efb553a8c 100644 --- a/gitlab/util.go +++ b/gitlab/util.go @@ -51,30 +51,26 @@ func validateValueFunc(values []string) schema.SchemaValidateFunc { } } -func validateDateFunc() schema.SchemaValidateFunc { - return func(v interface{}, k string) (we []string, errors []error) { - value := v.(string) - //add zero hours and let time figure out correctness - _, e := time.Parse(time.RFC3339, value+"T00:00:00Z") - if e != nil { - errors = append(errors, fmt.Errorf("%s is not valid for format YYYY-MM-DD", value)) - } - return +var validateDateFunc = func(v interface{}, k string) (we []string, errors []error) { + value := v.(string) + //add zero hours and let time figure out correctness + _, e := time.Parse(time.RFC3339, value+"T00:00:00Z") + if e != nil { + errors = append(errors, fmt.Errorf("%s is not valid for format YYYY-MM-DD", value)) } + return } -func validateURLFunc() schema.SchemaValidateFunc { - return func(v interface{}, k string) (s []string, errors []error) { - value := v.(string) - url, err := url.Parse(value) - - if err != nil || url.Host == "" || url.Scheme == "" { - errors = append(errors, fmt.Errorf("%s is not a valid URL", value)) - return - } +var validateURLFunc = func(v interface{}, k string) (s []string, errors []error) { + value := v.(string) + url, err := url.Parse(value) + if err != nil || url.Host == "" || url.Scheme == "" { + errors = append(errors, fmt.Errorf("%s is not a valid URL", value)) return } + + return } func stringToVisibilityLevel(s string) *gitlab.VisibilityValue { @@ -118,38 +114,34 @@ func stringToMergeMethod(s string) *gitlab.MergeMethodValue { return &value } -func StringIsGitlabVariableName() schema.SchemaValidateFunc { - return func(v interface{}, k string) (s []string, es []error) { - value, ok := v.(string) - if !ok { - es = append(es, fmt.Errorf("expected type of %s to be string", k)) - return - } - if len(value) < 1 || len(value) > 255 { - es = append(es, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %s", k, 1, 255, v)) - } - - match, _ := regexp.MatchString("[a-zA-Z0-9_]+", value) - if !match { - es = append(es, fmt.Errorf("%s is an invalid value for argument %s. Only A-Z, a-z, 0-9, and _ are allowed", value, k)) - } +var StringIsGitlabVariableName = func(v interface{}, k string) (s []string, es []error) { + value, ok := v.(string) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be string", k)) return } + if len(value) < 1 || len(value) > 255 { + es = append(es, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %s", k, 1, 255, v)) + } + + match, _ := regexp.MatchString("[a-zA-Z0-9_]+", value) + if !match { + es = append(es, fmt.Errorf("%s is an invalid value for argument %s. Only A-Z, a-z, 0-9, and _ are allowed", value, k)) + } + return } -func StringIsGitlabVariableType() schema.SchemaValidateFunc { - return func(v interface{}, k string) (s []string, es []error) { - value, ok := v.(string) - if !ok { - es = append(es, fmt.Errorf("expected type of %s to be string", k)) - return - } - variableType := stringToVariableType(value) - if variableType == nil { - es = append(es, fmt.Errorf("expected variable_type to be \"env_var\" or \"file\"")) - } +var StringIsGitlabVariableType = func(v interface{}, k string) (s []string, es []error) { + value, ok := v.(string) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be string", k)) return } + variableType := stringToVariableType(value) + if variableType == nil { + es = append(es, fmt.Errorf("expected variable_type to be \"env_var\" or \"file\"")) + } + return } // return the pieces of id `a:b` as a, b diff --git a/gitlab/util_test.go b/gitlab/util_test.go index e61499a2d..2777e93b7 100644 --- a/gitlab/util_test.go +++ b/gitlab/util_test.go @@ -91,10 +91,8 @@ func TestValidateURLFunc(t *testing.T) { }, } - validationFunc := validateURLFunc() - for _, tc := range cases { - _, errors := validationFunc(tc.Value, "test_arg") + _, errors := validateURLFunc(tc.Value, "test_arg") if len(errors) != tc.ErrCount { t.Fatalf("Expected 1 validation error")