diff --git a/go.mod b/go.mod index 42b4f685838..5caa606503b 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/hashicorp/go-multierror v1.0.0 github.com/hashicorp/golang-lru v0.5.3 github.com/imdario/mergo v0.3.8 // indirect - github.com/jenkins-x/go-scm v1.5.73 + github.com/jenkins-x/go-scm v1.5.79 github.com/json-iterator/go v1.1.8 // indirect github.com/markbates/inflect v1.0.4 // indirect github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index cc61d1fad2f..ac4c488ba2f 100644 --- a/go.sum +++ b/go.sum @@ -346,8 +346,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= -github.com/jenkins-x/go-scm v1.5.73 h1:ThyFuUdrKivXDHWStSmpQ/M7tJ331l7lzHtR5k5/RhY= -github.com/jenkins-x/go-scm v1.5.73/go.mod h1:PCT338UhP/pQ0IeEeMEf/hoLTYKcH7qjGEKd7jPkeYg= +github.com/jenkins-x/go-scm v1.5.79 h1:+HIEkc/Dzdq0buJF8q0Keip2wexW40BfkrDXKx88T78= +github.com/jenkins-x/go-scm v1.5.79/go.mod h1:PCT338UhP/pQ0IeEeMEf/hoLTYKcH7qjGEKd7jPkeYg= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= diff --git a/third_party/github.com/hashicorp/errwrap/go.mod b/third_party/github.com/hashicorp/errwrap/go.mod index d7ed369809b..c9b84022cf7 100644 --- a/third_party/github.com/hashicorp/errwrap/go.mod +++ b/third_party/github.com/hashicorp/errwrap/go.mod @@ -1,3 +1 @@ module github.com/hashicorp/errwrap - -go 1.13 diff --git a/third_party/github.com/hashicorp/go-multierror/go.mod b/third_party/github.com/hashicorp/go-multierror/go.mod index 8c91af65b26..2534331d5f9 100644 --- a/third_party/github.com/hashicorp/go-multierror/go.mod +++ b/third_party/github.com/hashicorp/go-multierror/go.mod @@ -1,5 +1,3 @@ module github.com/hashicorp/go-multierror require github.com/hashicorp/errwrap v1.0.0 - -go 1.13 diff --git a/third_party/github.com/jenkins-x/go-scm/scm/LICENSE b/third_party/github.com/jenkins-x/go-scm/scm/LICENSE deleted file mode 100644 index c76dc223a2b..00000000000 --- a/third_party/github.com/jenkins-x/go-scm/scm/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2017, Drone.IO Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/jenkins-x/go-scm/scm/client.go b/vendor/github.com/jenkins-x/go-scm/scm/client.go index 8ac0b2e867a..d1b1ea6ec4f 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/client.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/client.go @@ -94,8 +94,11 @@ type ( // Services used for communicating with the API. Driver Driver + Apps AppService Contents ContentService + Deployments DeploymentService Git GitService + GraphQL GraphQLService Organizations OrganizationService Issues IssueService PullRequests PullRequestService @@ -103,8 +106,6 @@ type ( Reviews ReviewService Users UserService Webhooks WebhookService - GraphQL GraphQLService - Apps AppService // DumpResponse optionally specifies a function to // dump the the response body for debugging purposes. diff --git a/vendor/github.com/jenkins-x/go-scm/scm/content.go b/vendor/github.com/jenkins-x/go-scm/scm/content.go index 7d4a567e387..b3f9cc9df7c 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/content.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/content.go @@ -40,7 +40,7 @@ type ( // Lists the files or directories at the given path List(ctx context.Context, repo, path, ref string) ([]*FileEntry, *Response, error) - // Create creates a new repositroy file. + // Create creates a new repository file. Create(ctx context.Context, repo, path string, params *ContentParams) (*Response, error) // Update updates a repository file. diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/data.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/data.go index 23d90114d8f..246f8fcf58c 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/data.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/data.go @@ -24,6 +24,11 @@ type Data struct { TestRef string PullRequestsCreated map[int]*scm.PullRequestInput PullRequestID int + CreateRepositories []*scm.RepositoryInput + Repositories []*scm.Repository + CurrentUser scm.User + Users []*scm.User + Hooks map[string][]*scm.Hook //All Labels That Exist In The Repo RepoLabelsExisting []string diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/fake.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/fake.go index ac1c7f6ce05..f44d3f262a6 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/fake.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/fake.go @@ -11,6 +11,9 @@ import ( // scm operations have been performed func NewDefault() (*scm.Client, *Data) { data := NewData() + data.CurrentUser.Login = "dummy" + data.CurrentUser.Name = "dummy" + client := &wrapper{new(scm.Client)} client.BaseURL = &url.URL{ Host: "fake.com", @@ -25,11 +28,11 @@ func NewDefault() (*scm.Client, *Data) { client.PullRequests = &pullService{client: client, data: data} client.Repositories = &repositoryService{client: client, data: data} client.Reviews = &reviewService{client: client, data: data} + client.Users = &userService{client: client, data: data} // TODO /* client.Contents = &contentService{client} - client.Users = &userService{client} client.Webhooks = &webhookService{client} */ return client.Client, data diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/repo.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/repo.go index c00da0be570..ad105bee95a 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/repo.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/fake/repo.go @@ -2,7 +2,9 @@ package fake import ( "context" + "fmt" "strings" + "time" "github.com/jenkins-x/go-scm/scm" ) @@ -36,6 +38,22 @@ func (s *repositoryService) FindUserPermission(ctx context.Context, repo string, // NormLogin normalizes login strings var NormLogin = strings.ToLower +func (s *repositoryService) FindHook(context.Context, string, string) (*scm.Hook, *scm.Response, error) { + panic("implement me") +} + +func (s *repositoryService) FindPerms(context.Context, string) (*scm.Perm, *scm.Response, error) { + panic("implement me") +} + +func (s *repositoryService) ListOrganisation(context.Context, string, scm.ListOptions) ([]*scm.Repository, *scm.Response, error) { + panic("implement me") +} + +func (s *repositoryService) ListUser(context.Context, string, scm.ListOptions) ([]*scm.Repository, *scm.Response, error) { + panic("implement me") +} + func (s *repositoryService) IsCollaborator(ctx context.Context, repo, login string) (bool, *scm.Response, error) { f := s.data normed := NormLogin(login) @@ -56,28 +74,17 @@ func (s *repositoryService) ListCollaborators(ctx context.Context, repo string) return result, nil, nil } -func (s *repositoryService) Find(context.Context, string) (*scm.Repository, *scm.Response, error) { - panic("implement me") -} - -func (s *repositoryService) FindHook(context.Context, string, string) (*scm.Hook, *scm.Response, error) { - panic("implement me") -} - -func (s *repositoryService) FindPerms(context.Context, string) (*scm.Perm, *scm.Response, error) { - panic("implement me") -} - -func (s *repositoryService) List(context.Context, scm.ListOptions) ([]*scm.Repository, *scm.Response, error) { - panic("implement me") +func (s *repositoryService) Find(ctx context.Context, fullName string) (*scm.Repository, *scm.Response, error) { + for _, repo := range s.data.Repositories { + if repo.FullName == fullName { + return repo, nil, nil + } + } + return nil, nil, scm.ErrNotFound } -func (s *repositoryService) ListOrganisation(context.Context, string, scm.ListOptions) ([]*scm.Repository, *scm.Response, error) { - panic("implement me") -} - -func (s *repositoryService) ListUser(context.Context, string, scm.ListOptions) ([]*scm.Repository, *scm.Response, error) { - panic("implement me") +func (s *repositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) { + return s.data.Repositories, nil, nil } func (s *repositoryService) ListLabels(context.Context, string, scm.ListOptions) ([]*scm.Label, *scm.Response, error) { @@ -89,10 +96,6 @@ func (s *repositoryService) ListLabels(context.Context, string, scm.ListOptions) return la, nil, nil } -func (s *repositoryService) ListHooks(context.Context, string, scm.ListOptions) ([]*scm.Hook, *scm.Response, error) { - panic("implement me") -} - func (s *repositoryService) ListStatus(ctx context.Context, repo string, ref string, opt scm.ListOptions) ([]*scm.Status, *scm.Response, error) { f := s.data result := make([]*scm.Status, 0, len(f.Statuses)) @@ -102,8 +105,45 @@ func (s *repositoryService) ListStatus(ctx context.Context, repo string, ref str return result, nil, nil } -func (s *repositoryService) CreateHook(context.Context, string, *scm.HookInput) (*scm.Hook, *scm.Response, error) { - panic("implement me") +func (s *repositoryService) Create(ctx context.Context, input *scm.RepositoryInput) (*scm.Repository, *scm.Response, error) { + s.data.CreateRepositories = append(s.data.CreateRepositories, input) + fullName := scm.Join(input.Namespace, input.Name) + repo := &scm.Repository{ + Namespace: input.Namespace, + Name: input.Name, + FullName: fullName, + Link: fmt.Sprintf("https://fake.com/%s.git", fullName), + Created: time.Now(), + } + s.data.Repositories = append(s.data.Repositories, repo) + return repo, nil, nil +} + +func (s *repositoryService) ListHooks(ctx context.Context, fullName string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) { + return s.data.Hooks[fullName], nil, nil +} + +func (s *repositoryService) CreateHook(ctx context.Context, fullName string, input *scm.HookInput) (*scm.Hook, *scm.Response, error) { + hook := &scm.Hook{ + ID: "dummy", + Name: input.Name, + Target: input.Target, + Active: true, + } + s.data.Hooks[fullName] = append(s.data.Hooks[fullName], hook) + return hook, nil, nil +} + +func (s *repositoryService) DeleteHook(ctx context.Context, fullName string, hookName string) (*scm.Response, error) { + hooks := s.data.Hooks[fullName] + for i, h := range hooks { + if h.Name == hookName { + hooks = append(hooks[0:i], hooks[i+1:]...) + s.data.Hooks[fullName] = hooks + break + } + } + return nil, nil } func (s *repositoryService) CreateStatus(ctx context.Context, repo string, ref string, in *scm.StatusInput) (*scm.Status, *scm.Response, error) { @@ -122,7 +162,3 @@ func (s *repositoryService) CreateStatus(ctx context.Context, repo string, ref s s.data.Statuses[ref] = statuses return status, nil, nil } - -func (s *repositoryService) DeleteHook(context.Context, string, string) (*scm.Response, error) { - panic("implement me") -} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/github/github.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/github/github.go index 42953980988..3e51c719934 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/driver/github/github.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/github/github.go @@ -39,6 +39,7 @@ func New(uri string) (*scm.Client, error) { // initialize services client.Driver = scm.DriverGithub client.Contents = &contentService{client} + client.Deployments = &deploymentService{client} client.Git = &gitService{client} client.Issues = &issueService{client} client.Organizations = &organizationService{client} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/github/repo.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/github/repo.go index 2c6014a8d03..093ace11d90 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/driver/github/repo.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/github/repo.go @@ -38,6 +38,13 @@ type repository struct { } `json:"permissions"` } +type repositoryInput struct { + Name string `json:"name"` + Description string `json:"description"` + Homepage string `json:"homepage"` + Private bool `json:"private"` +} + type hook struct { ID int `json:"id,omitempty"` Name string `json:"name"` @@ -199,6 +206,23 @@ func (s *repositoryService) ListLabels(ctx context.Context, repo string, opts sc return convertLabelObjects(out), res, err } +// Create creates a new repository +func (s *repositoryService) Create(ctx context.Context, input *scm.RepositoryInput) (*scm.Repository, *scm.Response, error) { + path := "/user/repos" + if input.Namespace != "" { + path = fmt.Sprintf("/orgs/%s/repos", input.Namespace) + + } + in := new(repositoryInput) + in.Name = input.Name + in.Description = input.Description + in.Homepage = input.Homepage + in.Private = input.Private + out := new(repository) + res, err := s.client.do(ctx, "POST", path, in, out) + return convertRepository(out), res, err +} + // CreateHook creates a new repository webhook. func (s *repositoryService) CreateHook(ctx context.Context, repo string, input *scm.HookInput) (*scm.Hook, *scm.Response, error) { path := fmt.Sprintf("repos/%s/hooks", repo) @@ -335,9 +359,19 @@ func convertCombinedStatus(from *combinedStatus) *scm.CombinedStatus { } func convertStatusList(from []*status) []*scm.Status { + // The GitHub API may return multiple statuses with the same Context, in + // reverse chronological order: + // https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref. + // We only expose the most recent one to consumers. to := []*scm.Status{} + unique := make(map[string]interface{}) for _, v := range from { - to = append(to, convertStatus(v)) + convertedStatus := convertStatus(v) + if _, ok := unique[convertedStatus.Label]; ok { + continue + } + to = append(to, convertedStatus) + unique[convertedStatus.Label] = nil } return to } diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/github/user.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/github/user.go index 9c3e823236f..8bac3f52c09 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/driver/github/user.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/github/user.go @@ -47,6 +47,9 @@ type user struct { } func convertUser(from *user) *scm.User { + if from == nil { + return nil + } return &scm.User{ Avatar: from.Avatar, Email: from.Email.String, diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/github/webhook.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/github/webhook.go index a565dea94e1..4ed8524bf5b 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/driver/github/webhook.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/github/webhook.go @@ -14,8 +14,8 @@ import ( "regexp" "time" + "github.com/jenkins-x/go-scm/pkg/hmac" "github.com/jenkins-x/go-scm/scm" - "github.com/jenkins-x/go-scm/scm/driver/internal/hmac" "github.com/jenkins-x/go-scm/scm/driver/internal/null" "github.com/sirupsen/logrus" ) @@ -106,6 +106,10 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo return hook, nil } + if logWebHooks { + log.Infof("Webhook HMAC token: %s", key) + } + sig := req.Header.Get("X-Hub-Signature") if !hmac.ValidatePrefix(data, []byte(key), sig) { return hook, scm.ErrSignatureInvalid diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/gitlab/repo.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/gitlab/repo.go index 83cd93110d2..ae52a8fbcfb 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/driver/gitlab/repo.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/gitlab/repo.go @@ -71,6 +71,10 @@ type repositoryService struct { client *wrapper } +func (s *repositoryService) Create(context.Context, *scm.RepositoryInput) (*scm.Repository, *scm.Response, error) { + panic("implement me") +} + func (s *repositoryService) FindCombinedStatus(ctx context.Context, repo, ref string) (*scm.CombinedStatus, *scm.Response, error) { panic("implement me") } diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/internal/hmac/hmac.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/internal/hmac/hmac.go deleted file mode 100644 index ba3fdf89df9..00000000000 --- a/vendor/github.com/jenkins-x/go-scm/scm/driver/internal/hmac/hmac.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package hmac - -import ( - "crypto/hmac" - "crypto/sha1" - "crypto/sha256" - "encoding/hex" - "hash" - "strings" -) - -// Validate checks the hmac signature of the mssasge -// using a hex encoded signature. -func Validate(h func() hash.Hash, message, key []byte, signature string) bool { - decoded, err := hex.DecodeString(signature) - if err != nil { - return false - } - return validate(h, message, key, decoded) -} - -// ValidatePrefix checks the hmac signature of the message -// using the message prefix to determine the signing algorithm. -func ValidatePrefix(message, key []byte, signature string) bool { - parts := strings.Split(signature, "=") - if len(parts) != 2 { - return false - } - switch parts[0] { - case "sha1": - return Validate(sha1.New, message, key, parts[1]) - case "sha256": - return Validate(sha256.New, message, key, parts[1]) - default: - return false - } -} - -func validate(h func() hash.Hash, message, key, signature []byte) bool { - mac := hmac.New(h, key) - mac.Write(message) - sum := mac.Sum(nil) - return hmac.Equal(signature, sum) -} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/repo.go b/vendor/github.com/jenkins-x/go-scm/scm/repo.go index 791ae3b747e..606b1becc3c 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/repo.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/repo.go @@ -26,6 +26,16 @@ type ( Updated time.Time } + // RepositoryInput provides the input fields required for + // creating a new repository. + RepositoryInput struct { + Namespace string + Name string + Description string + Homepage string + Private bool + } + // Perm represents a user's repository permissions. Perm struct { Pull bool @@ -126,6 +136,9 @@ type ( // FindCombinedStatus returns the combined status for a ref FindCombinedStatus(ctx context.Context, repo, ref string) (*CombinedStatus, *Response, error) + // Create creates a new repository . + Create(context.Context, *RepositoryInput) (*Repository, *Response, error) + // CreateHook creates a new repository webhook. CreateHook(context.Context, string, *HookInput) (*Hook, *Response, error) diff --git a/vendor/modules.txt b/vendor/modules.txt index f7da4d2f10d..d4aa6fdbfc2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -210,12 +210,12 @@ github.com/hashicorp/golang-lru github.com/hashicorp/golang-lru/simplelru # github.com/imdario/mergo v0.3.8 github.com/imdario/mergo -# github.com/jenkins-x/go-scm v1.5.73 +# github.com/jenkins-x/go-scm v1.5.79 +github.com/jenkins-x/go-scm/pkg/hmac github.com/jenkins-x/go-scm/scm github.com/jenkins-x/go-scm/scm/driver/fake github.com/jenkins-x/go-scm/scm/driver/github github.com/jenkins-x/go-scm/scm/driver/gitlab -github.com/jenkins-x/go-scm/scm/driver/internal/hmac github.com/jenkins-x/go-scm/scm/driver/internal/null # github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af github.com/jmespath/go-jmespath