From 1b21213085361842713d47b3741478422844c3a0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Feb 2023 16:46:03 +0000 Subject: [PATCH] Bump github.com/jenkins-x/go-scm from 1.13.1 to 1.13.2 Bumps [github.com/jenkins-x/go-scm](https://github.com/jenkins-x/go-scm) from 1.13.1 to 1.13.2. - [Release notes](https://github.com/jenkins-x/go-scm/releases) - [Changelog](https://github.com/jenkins-x/go-scm/blob/main/CHANGELOG.md) - [Commits](https://github.com/jenkins-x/go-scm/compare/v1.13.1...v1.13.2) --- updated-dependencies: - dependency-name: github.com/jenkins-x/go-scm dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../go-scm/scm/driver/azure/azure.go | 144 ++++ .../go-scm/scm/driver/azure/content.go | 210 +++++ .../jenkins-x/go-scm/scm/driver/azure/git.go | 303 +++++++ .../go-scm/scm/driver/azure/issue.go | 99 +++ .../jenkins-x/go-scm/scm/driver/azure/org.go | 67 ++ .../jenkins-x/go-scm/scm/driver/azure/pr.go | 255 ++++++ .../jenkins-x/go-scm/scm/driver/azure/repo.go | 272 ++++++ .../go-scm/scm/driver/azure/review.go | 47 ++ .../jenkins-x/go-scm/scm/driver/azure/user.go | 47 ++ .../go-scm/scm/driver/azure/webhook.go | 789 ++++++++++++++++++ .../jenkins-x/go-scm/scm/factory/factory.go | 13 + vendor/modules.txt | 3 +- 14 files changed, 2251 insertions(+), 4 deletions(-) create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/azure.go create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/content.go create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/git.go create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/issue.go create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/org.go create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/pr.go create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/repo.go create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/review.go create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/user.go create mode 100644 vendor/github.com/jenkins-x/go-scm/scm/driver/azure/webhook.go diff --git a/go.mod b/go.mod index 3f291f579d6..8a5d82b40f4 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/hashicorp/errwrap v1.1.0 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/golang-lru v0.5.4 - github.com/jenkins-x/go-scm v1.13.1 + github.com/jenkins-x/go-scm v1.13.2 github.com/mitchellh/go-homedir v1.1.0 github.com/opencontainers/image-spec v1.1.0-rc2 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index f8d8bac266c..0f820704ee1 100644 --- a/go.sum +++ b/go.sum @@ -732,8 +732,8 @@ github.com/jcmturner/gokrb5/v8 v8.4.2/go.mod h1:sb+Xq/fTY5yktf/VxLsE3wlfPqQjp0aW github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jellydator/ttlcache/v2 v2.11.1 h1:AZGME43Eh2Vv3giG6GeqeLeFXxwxn1/qHItqWZl6U64= github.com/jellydator/ttlcache/v2 v2.11.1/go.mod h1:RtE5Snf0/57e+2cLWFYWCCsLas2Hy3c5Z4n14XmSvTI= -github.com/jenkins-x/go-scm v1.13.1 h1:9PPeH5c+gPvtdGKZDktzlgf3sVA6L34pBYcvrXZbnhs= -github.com/jenkins-x/go-scm v1.13.1/go.mod h1:GyT1710F6sTolj1Aiq5tmWxIzAWMp5rnMUQIYAdmw68= +github.com/jenkins-x/go-scm v1.13.2 h1:+jzbfA7E8dtKnrncTxYfC9r+Hwyve6x5ErzqZSHUBa4= +github.com/jenkins-x/go-scm v1.13.2/go.mod h1:AwQT5G4ZfZt7ALzj8T0Vd5vsK5MmU74fJtWWDp/nLKk= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jhump/protoreflect v1.14.0 h1:MBbQK392K3u8NTLbKOCIi3XdI+y+c6yt5oMq0X3xviw= diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/azure.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/azure.go new file mode 100644 index 00000000000..3b3246abc2f --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/azure.go @@ -0,0 +1,144 @@ +// 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 azure implements a azure client. +package azure + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "net/url" + "strings" + + "github.com/jenkins-x/go-scm/scm" +) + +// New returns a new azure API client. +func New(uri string) (*scm.Client, error) { + base, err := url.Parse(uri) + if err != nil { + return nil, err + } + if !strings.HasSuffix(base.Path, "/") { + base.Path += "/" + } + client := &wrapper{ + new(scm.Client), + } + client.BaseURL = base + // initialize services + client.Driver = scm.DriverAzure + client.Contents = &contentService{client} + client.Git = &gitService{client} + client.Issues = &issueService{client} + client.Organizations = &organizationService{client} + client.PullRequests = &pullService{&issueService{client}} + client.Repositories = &RepositoryService{client} + client.Reviews = &reviewService{client} + client.Users = &userService{client} + client.Webhooks = &webhookService{client} + return client.Client, nil +} + +// NewDefault returns a new azure API client. +func NewDefault() *scm.Client { + client, _ := New("https://dev.azure.com") + return client +} + +// wrapper wraps the Client to provide high level helper functions for making http requests and unmarshaling the response. +type wrapper struct { + *scm.Client +} + +// do wraps the Client.Do function by creating the Request and unmarshalling the response. +func (c *wrapper) do(ctx context.Context, method, path string, in, out interface{}) (*scm.Response, error) { + req := &scm.Request{ + Method: method, + Path: path, + } + // if we are posting or putting data, we need to write it to the body of the request. + if in != nil { + buf := new(bytes.Buffer) + _ = json.NewEncoder(buf).Encode(in) + req.Header = map[string][]string{ + "Content-Type": {"application/json"}, + } + req.Body = buf + } + // execute the http request + res, err := c.Client.Do(ctx, req) + if err != nil { + return nil, err + } + defer res.Body.Close() + + // error response. + if res.Status > 300 { + err := new(Error) + _ = json.NewDecoder(res.Body).Decode(err) + return res, err + } + // the following is used for debugging purposes. + // bytes, err := io.ReadAll(res.Body) + // if err != nil { + // log.Fatal(err) + // } + // fmt.Println(string(bytes)) + + if out == nil { + return res, nil + } + // if a json response is expected, parse and return the json response. + decodeErr := json.NewDecoder(res.Body).Decode(out) + // following line is used for debugging purposes. + // _ = json.NewEncoder(os.Stdout).Encode(out) + return res, decodeErr +} + +// Error represents am Azure error. +type Error struct { + Message string `json:"message"` +} + +func (e *Error) Error() string { + return e.Message +} + +func SanitizeBranchName(name string) string { + if strings.Contains(name, "/") { + return name + } + return "refs/heads/" + name +} + +type repoObj struct { + org string + project string + name string +} + +func decodeRepo(repo string) (*repoObj, error) { + repoTrimmed := strings.Trim(repo, "/") + repoParts := strings.Split(repoTrimmed, "/") + // test for correct number of values + if len(repoParts) != 3 { + return nil, fmt.Errorf("expected repository in form //, but got %s", repoTrimmed) + } + + // Test for empty values + for _, s := range repoParts { + if s == "" { + return nil, fmt.Errorf("expected repository in form //, but got %s", repoTrimmed) + } + } + + return &repoObj{ + org: repoParts[0], + project: repoParts[1], + name: repoParts[2], + }, nil +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/content.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/content.go new file mode 100644 index 00000000000..ada51a18ea2 --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/content.go @@ -0,0 +1,210 @@ +// 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 azure + +import ( + "context" + "encoding/base64" + "fmt" + + "github.com/jenkins-x/go-scm/scm" +) + +type contentService struct { + client *wrapper +} + +func (s *contentService) Find(ctx context.Context, repo, path, ref string) (*scm.Content, *scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/items/get?view=azure-devops-rest-6.0 + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/items?path=%s&includeContent=true&$format=json", ro.org, ro.project, ro.name, path) + endpoint += generateURIFromRef(ref) + endpoint += "&api-version=6.0" + out := new(content) + res, err := s.client.do(ctx, "GET", endpoint, nil, out) + data := []byte(out.Content) + return &scm.Content{ + Path: out.Path, + Data: data, + Sha: out.CommitID, + BlobID: out.ObjectID, + }, res, err +} + +func (s *contentService) Create(ctx context.Context, repo, path string, params *scm.ContentParams) (*scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, err + } + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/pushes?api-version=6.0", ro.org, ro.project, ro.name) + ref := refUpdate{ + Name: SanitizeBranchName(params.Branch), + OldObjectID: params.Ref, + } + cha := change{ + ChangeType: "add", + } + cha.Item.Path = path + cha.NewContent.Content = base64.StdEncoding.EncodeToString(params.Data) + cha.NewContent.ContentType = "base64encoded" + + com := commit{ + Comment: params.Message, + Changes: []change{cha}, + } + in := &contentCreateUpdate{ + RefUpdates: []refUpdate{ref}, + Commits: []commit{com}, + } + + res, err := s.client.do(ctx, "POST", endpoint, in, nil) + return res, err +} + +func (s *contentService) Update(ctx context.Context, repo, path string, params *scm.ContentParams) (*scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, err + } + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/pushes?api-version=6.0", ro.org, ro.project, ro.name) + ref := refUpdate{ + Name: SanitizeBranchName(params.Branch), + OldObjectID: params.Sha, + } + cha := change{ + ChangeType: "edit", + } + cha.Item.Path = path + cha.NewContent.Content = base64.StdEncoding.EncodeToString(params.Data) + cha.NewContent.ContentType = "base64encoded" + + com := commit{ + Comment: params.Message, + Changes: []change{cha}, + } + in := &contentCreateUpdate{ + RefUpdates: []refUpdate{ref}, + Commits: []commit{com}, + } + + res, err := s.client.do(ctx, "POST", endpoint, in, nil) + return res, err +} + +func (s *contentService) Delete(ctx context.Context, repo, path string, params *scm.ContentParams) (*scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, err + } + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/pushes?api-version=6.0", ro.org, ro.project, ro.name) + ref := refUpdate{ + Name: SanitizeBranchName(params.Branch), + OldObjectID: params.Sha, + } + change1 := change{ + ChangeType: "delete", + } + change1.Item.Path = path + com := commit{ + Comment: params.Message, + Changes: []change{change1}, + } + in := &contentCreateUpdate{ + RefUpdates: []refUpdate{ref}, + Commits: []commit{com}, + } + + res, err := s.client.do(ctx, "POST", endpoint, in, nil) + return res, err +} + +func (s *contentService) List(ctx context.Context, repo, path, ref string) ([]*scm.FileEntry, *scm.Response, error) { + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/items/list?view=azure-devops-rest-6.0 + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/items?path=%s&recursionLevel=Full&$format=json", ro.org, ro.project, ro.name, path) + endpoint += generateURIFromRef(ref) + out := new(contentList) + res, err := s.client.do(ctx, "GET", endpoint, nil, &out) + return convertFileEntryList(out.Value), res, err +} + +type content struct { + ObjectID string `json:"objectId"` + GitObjectType string `json:"gitObjectType"` + CommitID string `json:"commitId"` + Path string `json:"path"` + Content string `json:"content"` + URL string `json:"url"` + Links struct { + Self struct { + Href string `json:"href"` + } `json:"self"` + Repository struct { + Href string `json:"href"` + } `json:"repository"` + Blob struct { + Href string `json:"href"` + } `json:"blob"` + } `json:"_links"` +} + +type contentList struct { + Count int `json:"count"` + Value []*content `json:"value"` +} +type refUpdate struct { + Name string `json:"name"` + OldObjectID string `json:"oldObjectId,omitempty"` +} +type change struct { + ChangeType string `json:"changeType"` + Item struct { + Path string `json:"path"` + } `json:"item"` + NewContent struct { + Content string `json:"content,omitempty"` + ContentType string `json:"contentType,omitempty"` + } `json:"newContent,omitempty"` +} +type commit struct { + Comment string `json:"comment"` + Changes []change `json:"changes"` +} +type contentCreateUpdate struct { + RefUpdates []refUpdate `json:"refUpdates"` + Commits []commit `json:"commits"` +} + +func convertFileEntryList(from []*content) []*scm.FileEntry { + to := []*scm.FileEntry{} + for _, v := range from { + to = append(to, convertFileEntry(v)) + } + return to +} +func convertFileEntry(from *content) *scm.FileEntry { + return &scm.FileEntry{Path: from.Path, Sha: from.CommitID} +} + +func generateURIFromRef(ref string) (uri string) { + if ref != "" { + if len(ref) == 40 { + return fmt.Sprintf("&versionDescriptor.versionType=commit&versionDescriptor.version=%s", ref) + } + return fmt.Sprintf("&versionDescriptor.versionType=branch&versionDescriptor.version=%s", ref) + } + return "" +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/git.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/git.go new file mode 100644 index 00000000000..8be89cbb44e --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/git.go @@ -0,0 +1,303 @@ +// 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 azure + +import ( + "context" + "fmt" + "time" + + "github.com/jenkins-x/go-scm/scm" +) + +type gitService struct { + client *wrapper +} + +func (s *gitService) FindRef(ctx context.Context, repo, ref string) (string, *scm.Response, error) { + return "", nil, scm.ErrNotSupported +} + +func (s *gitService) DeleteRef(ctx context.Context, repo, ref string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *gitService) CreateRef(ctx context.Context, repo, ref, sha string) (*scm.Reference, *scm.Response, error) { + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/refs/update-refs?view=azure-devops-rest-6.0 + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/refs?api-version=6.0", ro.org, ro.project, ro.name) + + in := make(gitRefs, 1) + in[0].Name = scm.ExpandRef(ref, "refs/heads") + in[0].NewObjectID = sha + in[0].OldObjectID = "0000000000000000000000000000000000000000" + + out := gitRefsResult{} + res, err := s.client.do(ctx, "POST", endpoint, in, &out) + + return findGitRef(out, ref, in[0].Name), res, err + +} + +func (s *gitService) FindBranch(ctx context.Context, repo, name string) (*scm.Reference, *scm.Response, error) { + _, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + return nil, nil, scm.ErrNotSupported +} + +func (s *gitService) FindCommit(ctx context.Context, repo, ref string) (*scm.Commit, *scm.Response, error) { + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/commits/get?view=azure-devops-rest-6.0#get-by-id + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/commits/%s?api-version=6.0", ro.org, ro.project, ro.name, ref) + out := new(gitCommit) + res, err := s.client.do(ctx, "GET", endpoint, nil, out) + return convertCommit(out), res, err +} + +func (s *gitService) FindTag(ctx context.Context, repo, name string) (*scm.Reference, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *gitService) ListBranches(ctx context.Context, repo string, _ *scm.ListOptions) ([]*scm.Reference, *scm.Response, error) { + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/refs/list?view=azure-devops-rest-6.0 + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/refs?includeMyBranches=true&api-version=6.0", ro.org, ro.project, ro.name) + out := new(branchList) + res, err := s.client.do(ctx, "GET", endpoint, nil, &out) + return convertBranchList(out.Value), res, err +} + +func (s *gitService) ListCommits(ctx context.Context, repo string, opts scm.CommitListOptions) ([]*scm.Commit, *scm.Response, error) { + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/commits/get-commits?view=azure-devops-rest-6.0 + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/commits?", ro.org, ro.project, ro.name) + if opts.Ref != "" { + endpoint += fmt.Sprintf("searchCriteria.itemVersion.version=%s&", opts.Ref) + } + if opts.Path != "" { + endpoint += fmt.Sprintf("searchCriteria.itemPath=%s&", opts.Path) + } + endpoint += "api-version=6.0" + + out := new(commitList) + res, err := s.client.do(ctx, "GET", endpoint, nil, &out) + return convertCommitList(out.Value), res, err +} + +func (s *gitService) ListTags(ctx context.Context, repo string, opts *scm.ListOptions) ([]*scm.Reference, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *gitService) ListChanges(ctx context.Context, repo, ref string, _ *scm.ListOptions) ([]*scm.Change, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *gitService) CompareCommits(ctx context.Context, repo, source, target string, _ *scm.ListOptions) ([]*scm.Change, *scm.Response, error) { + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/diffs/get?view=azure-devops-rest-6.0 + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/diffs/commits?", ro.org, ro.project, ro.name) + // add base + endpoint += fmt.Sprintf("baseVersion=%s&baseVersionType=commit&", source) + // add target + endpoint += fmt.Sprintf("targetVersion=%s&targetVersionType=commit&api-version=6.0", target) + out := new(compare) + res, err := s.client.do(ctx, "GET", endpoint, nil, &out) + + changes := out.Changes + return convertChangeList(changes), res, err +} + +type gitRef struct { + Name string `json:"name"` + OldObjectID string `json:"oldObjectId"` + NewObjectID string `json:"newObjectId"` +} + +type gitRefsResult struct { + Value gitRefs `json:"value"` + Count int `json:"count"` +} +type gitRefs []gitRef + +type branchList struct { + Value []*branch `json:"value"` + Count int `json:"count"` +} + +type branch struct { + Name string `json:"name"` + ObjectID string `json:"objectId"` + Creator struct { + DisplayName string `json:"displayName"` + URL string `json:"url"` + Links struct { + Avatar struct { + Href string `json:"href"` + } `json:"avatar"` + } `json:"_links"` + ID string `json:"id"` + UniqueName string `json:"uniqueName"` + ImageURL string `json:"imageUrl"` + Descriptor string `json:"descriptor"` + } `json:"creator"` + URL string `json:"url"` +} + +type commitList struct { + Value []*gitCommit `json:"value"` + Count int `json:"count"` +} +type gitCommit struct { + CommitID string `json:"commitId"` + Author struct { + Name string `json:"name"` + Email string `json:"email"` + Date time.Time `json:"date"` + } `json:"author"` + Committer struct { + Name string `json:"name"` + Email string `json:"email"` + Date time.Time `json:"date"` + } `json:"committer"` + Comment string `json:"comment"` + CommentTruncated bool `json:"commentTruncated"` + ChangeCounts struct { + Add int `json:"Add"` + Edit int `json:"Edit"` + Delete int `json:"Delete"` + } `json:"changeCounts"` + URL string `json:"url"` + RemoteURL string `json:"remoteUrl"` +} + +type file struct { + ChangeType string `json:"changeType"` + Item struct { + CommitID string `json:"commitId"` + GitObjectType string `json:"gitObjectType"` + IsFolder bool `json:"isFolder"` + ObjectID string `json:"objectId"` + OriginalObjectID string `json:"originalObjectId"` + Path string `json:"path"` + URL string `json:"url"` + } `json:"item"` +} + +type compare struct { + AheadCount int64 `json:"aheadCount"` + AllChangesIncluded bool `json:"allChangesIncluded"` + BaseCommit string `json:"baseCommit"` + BehindCount int64 `json:"behindCount"` + ChangeCounts struct { + Add int64 `json:"Add"` + Edit int64 `json:"Edit"` + } `json:"changeCounts"` + Changes []*file `json:"changes"` + CommonCommit string `json:"commonCommit"` + TargetCommit string `json:"targetCommit"` +} + +func convertBranchList(from []*branch) []*scm.Reference { + to := []*scm.Reference{} + for _, v := range from { + to = append(to, convertBranch(v)) + } + return to +} + +func findGitRef(from gitRefsResult, refName, refPath string) *scm.Reference { + for _, ref := range from.Value { + if ref.Name == refPath { + return &scm.Reference{ + Name: refName, + Path: refPath, + Sha: ref.NewObjectID, + } + } + } + return &scm.Reference{} +} + +func convertBranch(from *branch) *scm.Reference { + return &scm.Reference{ + Name: scm.TrimRef(from.Name), + Path: from.Name, + Sha: from.ObjectID, + } +} + +func convertCommitList(from []*gitCommit) []*scm.Commit { + to := []*scm.Commit{} + for _, v := range from { + to = append(to, convertCommit(v)) + } + return to +} + +func convertCommit(from *gitCommit) *scm.Commit { + return &scm.Commit{ + Message: from.Comment, + Sha: from.CommitID, + Link: from.URL, + Author: scm.Signature{ + Login: from.Author.Name, + Name: from.Author.Name, + Email: from.Author.Email, + Date: from.Author.Date, + }, + Committer: scm.Signature{ + Login: from.Committer.Name, + Name: from.Committer.Name, + Email: from.Committer.Email, + Date: from.Committer.Date, + }, + } +} + +func convertChangeList(from []*file) []*scm.Change { + to := []*scm.Change{} + for _, v := range from { + to = append(to, convertChange(v)) + } + return to +} + +func convertChange(from *file) *scm.Change { + returnVal := &scm.Change{ + Path: from.Item.Path, + } + switch from.ChangeType { + case "add": + returnVal.Added = true + case "delete": + returnVal.Deleted = true + case "rename": + returnVal.Renamed = true + } + + return returnVal +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/issue.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/issue.go new file mode 100644 index 00000000000..d94bf29c66c --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/issue.go @@ -0,0 +1,99 @@ +// 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 azure + +import ( + "context" + + "github.com/jenkins-x/go-scm/scm" +) + +type issueService struct { + client *wrapper +} + +func (s *issueService) Search(ctx context.Context, options scm.SearchOptions) ([]*scm.SearchIssue, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) ListLabels(ctx context.Context, s2 string, i int, options *scm.ListOptions) ([]*scm.Label, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) ListEvents(ctx context.Context, s2 string, i int, options *scm.ListOptions) ([]*scm.ListedIssueEvent, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) EditComment(ctx context.Context, s2 string, i, i2 int, input *scm.CommentInput) (*scm.Comment, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) Reopen(ctx context.Context, s2 string, i int) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) AddLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) DeleteLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) AssignIssue(ctx context.Context, repo string, number int, logins []string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) UnassignIssue(ctx context.Context, repo string, number int, logins []string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) SetMilestone(ctx context.Context, repo string, issueID, number int) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) ClearMilestone(ctx context.Context, repo string, id int) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) Find(ctx context.Context, repo string, number int) (*scm.Issue, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) FindComment(ctx context.Context, repo string, index, id int) (*scm.Comment, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) List(ctx context.Context, repo string, opts scm.IssueListOptions) ([]*scm.Issue, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) ListComments(ctx context.Context, repo string, index int, opts *scm.ListOptions) ([]*scm.Comment, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) Create(ctx context.Context, repo string, input *scm.IssueInput) (*scm.Issue, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) CreateComment(ctx context.Context, repo string, number int, input *scm.CommentInput) (*scm.Comment, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *issueService) DeleteComment(ctx context.Context, repo string, number, id int) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) Close(ctx context.Context, repo string, number int) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) Lock(ctx context.Context, repo string, number int) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *issueService) Unlock(ctx context.Context, repo string, number int) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/org.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/org.go new file mode 100644 index 00000000000..1cb22c1d709 --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/org.go @@ -0,0 +1,67 @@ +// 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 azure + +import ( + "context" + + "github.com/jenkins-x/go-scm/scm" +) + +type organizationService struct { + client *wrapper +} + +func (s *organizationService) Create(ctx context.Context, input *scm.OrganizationInput) (*scm.Organization, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *organizationService) Delete(ctx context.Context, s2 string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *organizationService) ListTeams(ctx context.Context, org string, ops *scm.ListOptions) ([]*scm.Team, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *organizationService) IsMember(ctx context.Context, org, user string) (bool, *scm.Response, error) { + return false, nil, scm.ErrNotSupported +} + +func (s *organizationService) IsAdmin(ctx context.Context, org, user string) (bool, *scm.Response, error) { + return false, nil, scm.ErrNotSupported +} + +func (s *organizationService) ListTeamMembers(ctx context.Context, id int, role string, ops *scm.ListOptions) ([]*scm.TeamMember, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *organizationService) ListOrgMembers(ctx context.Context, org string, ops *scm.ListOptions) ([]*scm.TeamMember, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *organizationService) ListPendingInvitations(ctx context.Context, org string, ops *scm.ListOptions) ([]*scm.OrganizationPendingInvite, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *organizationService) AcceptOrganizationInvitation(ctx context.Context, org string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *organizationService) ListMemberships(ctx context.Context, opts *scm.ListOptions) ([]*scm.Membership, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *organizationService) Find(ctx context.Context, name string) (*scm.Organization, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *organizationService) FindMembership(ctx context.Context, name, username string) (*scm.Membership, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *organizationService) List(ctx context.Context, opts *scm.ListOptions) ([]*scm.Organization, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/pr.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/pr.go new file mode 100644 index 00000000000..52d168e57a6 --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/pr.go @@ -0,0 +1,255 @@ +// 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 azure + +import ( + "context" + "fmt" + "time" + + "github.com/jenkins-x/go-scm/scm" + "github.com/jenkins-x/go-scm/scm/driver/internal/null" +) + +type pullService struct { + *issueService +} + +func (s *pullService) Update(ctx context.Context, s2 string, i int, input *scm.PullRequestInput) (*scm.PullRequest, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *pullService) RequestReview(ctx context.Context, repo string, number int, logins []string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *pullService) UnrequestReview(ctx context.Context, repo string, number int, logins []string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *pullService) Find(ctx context.Context, repo string, number int) (*scm.PullRequest, *scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull-requests/get-pull-request?view=azure-devops-rest-6.0 + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/pullrequests/%d?api-version=6.0", + ro.org, ro.project, ro.name, number) + out := new(pr) + res, err := s.client.do(ctx, "GET", endpoint, nil, out) + return convertPullRequest(out), res, err +} + +func (s *pullService) List(ctx context.Context, repo string, opts *scm.PullRequestListOptions) ([]*scm.PullRequest, *scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull-requests/get-pull-request?view=azure-devops-rest-6.0 + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/pullrequests?api-version=6.0", ro.org, ro.project, ro.name) + out := new(prList) + res, err := s.client.do(ctx, "GET", endpoint, nil, out) + return convertPullRequests(out), res, err +} + +func (s *pullService) ListChanges(ctx context.Context, repo string, number int, opts *scm.ListOptions) ([]*scm.Change, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *pullService) ListCommits(ctx context.Context, repo string, number int, opts *scm.ListOptions) ([]*scm.Commit, *scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull-request-commits/get-pull-request-commits?view=azure-devops-rest-6.0 + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/pullRequests/%d/commits?api-version=6.0", + ro.org, ro.project, ro.name, number) + out := new(commitList) + res, err := s.client.do(ctx, "GET", endpoint, nil, out) + return convertCommitList(out.Value), res, err +} + +func (s *pullService) Merge(ctx context.Context, repo string, number int, opts *scm.PullRequestMergeOptions) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *pullService) Close(ctx context.Context, repo string, number int) (*scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, err + } + + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull-request-commits/get-pull-request-commits?view=azure-devops-rest-6.0 + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/pullRequests/%d?api-version=6.0", + ro.org, ro.project, ro.name, number) + body := prUpdateInput{ + Status: PrAbandoned, + } + res, err := s.client.do(ctx, "PATCH", endpoint, body, nil) + return res, err +} + +func (s *pullService) Create(ctx context.Context, repo string, input *scm.PullRequestInput) (*scm.PullRequest, *scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull-requests/create?view=azure-devops-rest-6.0 + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s/pullrequests?api-version=6.0", ro.org, ro.project, ro.name) + in := &prInput{ + Title: input.Title, + Description: input.Body, + SourceRefName: scm.ExpandRef(input.Head, "refs/heads"), + TargetRefName: scm.ExpandRef(input.Base, "refs/heads"), + } + out := new(pr) + res, err := s.client.do(ctx, "POST", endpoint, in, out) + return convertPullRequest(out), res, err +} + +type prInput struct { + SourceRefName string `json:"sourceRefName"` + TargetRefName string `json:"targetRefName"` + Title string `json:"title"` + Description string `json:"description"` + Reviewers []struct { + ID string `json:"id"` + } `json:"reviewers"` +} + +type pr struct { + Repository struct { + ID string `json:"id"` + Name string `json:"name"` + URL string `json:"url"` + WebURL string `json:"webUrl"` + Project struct { + ID string `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + URL string `json:"url"` + State string `json:"state"` + Revision int `json:"revision"` + } `json:"project"` + RemoteURL string `json:"remoteUrl"` + } `json:"repository"` + PullRequestID int `json:"pullRequestId"` + CodeReviewID int `json:"codeReviewId"` + Status string `json:"status"` + CreatedBy struct { + ID string `json:"id"` + DisplayName string `json:"displayName"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + ImageURL string `json:"imageUrl"` + } `json:"createdBy"` + CreationDate time.Time `json:"creationDate"` + ClosedDate null.String `json:"closedDate"` + Title string `json:"title"` + Description string `json:"description"` + SourceRefName string `json:"sourceRefName"` + TargetRefName string `json:"targetRefName"` + MergeStatus string `json:"mergeStatus"` + MergeID string `json:"mergeId"` + LastMergeSourceCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeSourceCommit"` + LastMergeTargetCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeTargetCommit"` + Reviewers []struct { + ReviewerURL string `json:"reviewerUrl"` + Vote int `json:"vote"` + ID string `json:"id"` + DisplayName string `json:"displayName"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + ImageURL string `json:"imageUrl"` + } `json:"reviewers"` + URL string `json:"url"` + Links struct { + Self struct { + Href string `json:"href"` + } `json:"self"` + Repository struct { + Href string `json:"href"` + } `json:"repository"` + WorkItems struct { + Href string `json:"href"` + } `json:"workItems"` + SourceBranch struct { + Href string `json:"href"` + } `json:"sourceBranch"` + TargetBranch struct { + Href string `json:"href"` + } `json:"targetBranch"` + SourceCommit struct { + Href string `json:"href"` + } `json:"sourceCommit"` + TargetCommit struct { + Href string `json:"href"` + } `json:"targetCommit"` + CreatedBy struct { + Href string `json:"href"` + } `json:"createdBy"` + Iterations struct { + Href string `json:"href"` + } `json:"iterations"` + } `json:"_links"` + SupportsIterations bool `json:"supportsIterations"` + ArtifactID string `json:"artifactId"` +} + +type prList struct { + Values []pr `json:"value"` +} + +var ( + PrAbandoned = "abandoned" +) + +type prUpdateInput struct { + Status string `json:"status"` +} + +func convertPullRequests(from *prList) []*scm.PullRequest { + var prs []*scm.PullRequest + for index := range from.Values { + prs = append(prs, convertPullRequest(&from.Values[index])) + } + return prs +} + +func convertPullRequest(from *pr) *scm.PullRequest { + return &scm.PullRequest{ + Number: from.PullRequestID, + Title: from.Title, + Body: from.Description, + Sha: from.LastMergeSourceCommit.CommitID, + Source: scm.TrimRef(from.SourceRefName), + Target: scm.TrimRef(from.TargetRefName), + Link: fmt.Sprintf("%s/pullrequest/%d", from.Repository.WebURL, from.PullRequestID), + Closed: from.ClosedDate.Valid, + Merged: from.Status == "completed", + Ref: fmt.Sprintf("refs/pull/%d/merge", from.PullRequestID), + Head: scm.PullRequestBranch{ + Sha: from.LastMergeSourceCommit.CommitID, + }, + Base: scm.PullRequestBranch{ + Sha: from.LastMergeTargetCommit.CommitID, + }, + Author: scm.User{ + Login: from.CreatedBy.UniqueName, + Avatar: from.CreatedBy.ImageURL, + }, + Created: from.CreationDate, + } +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/repo.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/repo.go new file mode 100644 index 00000000000..0e96b87b3f0 --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/repo.go @@ -0,0 +1,272 @@ +// 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 azure + +import ( + "context" + "fmt" + "net/url" + "strings" + + "github.com/jenkins-x/go-scm/scm" +) + +// RepositoryService implements the repository service for +// the GitHub driver. +type RepositoryService struct { + client *wrapper +} + +// ListOrganisation lists all the repos for an org or specific project in an org +// org can be in the form "" or "" +func (s *RepositoryService) ListOrganisation(ctx context.Context, org string, options *scm.ListOptions) ([]*scm.Repository, *scm.Response, error) { + orgTrimmed := strings.Trim(org, "/") + orgParts := strings.Split(orgTrimmed, "/") + + if len(orgParts) > 2 || len(orgParts) < 1 { + return nil, nil, fmt.Errorf("expected org in form or /, but got %s", orgTrimmed) + } + + for _, s := range orgParts { + if s == "" { + return nil, nil, fmt.Errorf("expected org in form or /, but got %s", orgTrimmed) + } + } + + endpoint := fmt.Sprintf("%s/_apis/git/repositories?api-version=6.0", orgTrimmed) + + out := new(repositories) + res, err := s.client.do(ctx, "GET", endpoint, nil, &out) + + return convertRepositoryList(out, options), res, err +} + +func (s *RepositoryService) ListUser(ctx context.Context, s2 string, options *scm.ListOptions) ([]*scm.Repository, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *RepositoryService) ListLabels(ctx context.Context, s2 string, options *scm.ListOptions) ([]*scm.Label, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *RepositoryService) FindCombinedStatus(ctx context.Context, repo, ref string) (*scm.CombinedStatus, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *RepositoryService) Create(ctx context.Context, input *scm.RepositoryInput) (*scm.Repository, *scm.Response, error) { + ro, err := decodeRepo(input.Namespace + "/" + input.Name) + if err != nil { + return nil, nil, err + } + + proj, res, err := s.getProject(ctx, ro) + if err != nil { + return nil, res, err + } + + in := repository{ + Name: input.Name, + Project: struct { + ID string `json:"id"` + Name string `json:"name"` + State string `json:"state"` + URL string `json:"url"` + }{ + ID: proj.ID, + }, + } + out := new(repository) + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories?api-version=6.0", ro.org, ro.project) + + res, err = s.client.do(ctx, "POST", endpoint, &in, &out) + return convertRepository(out), res, err +} + +func (s *RepositoryService) Fork(ctx context.Context, input *scm.RepositoryInput, s2 string) (*scm.Repository, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *RepositoryService) IsCollaborator(ctx context.Context, repo, user string) (bool, *scm.Response, error) { + return false, nil, scm.ErrNotSupported +} + +func (s *RepositoryService) AddCollaborator(ctx context.Context, repo, user, permission string) (bool, bool, *scm.Response, error) { + return false, false, nil, scm.ErrNotSupported +} + +func (s *RepositoryService) ListCollaborators(ctx context.Context, repo string, ops *scm.ListOptions) ([]scm.User, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *RepositoryService) FindUserPermission(ctx context.Context, repo, user string) (string, *scm.Response, error) { + return "", nil, scm.ErrNotSupported +} + +func (s *RepositoryService) Delete(ctx context.Context, repo string) (*scm.Response, error) { + ro, err := decodeRepo(repo) + if err != nil { + return nil, err + } + + requestRepo, res, err := s.find(ctx, ro) + if err != nil { + return res, err + } + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s?api-version=6.0", ro.org, ro.project, requestRepo.ID) + + res, err = s.client.do(ctx, "DELETE", endpoint, nil, nil) + return res, err +} + +// Find returns the repository by name. +func (s *RepositoryService) Find(ctx context.Context, repo string) (*scm.Repository, *scm.Response, error) { + // https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/get?view=azure-devops-rest-4.1 + ro, err := decodeRepo(repo) + if err != nil { + return nil, nil, err + } + + return s.find(ctx, ro) +} + +func (s *RepositoryService) find(ctx context.Context, ro *repoObj) (*scm.Repository, *scm.Response, error) { + + endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s?api-version=6.0", ro.org, ro.project, ro.name) + + out := new(repository) + res, err := s.client.do(ctx, "GET", endpoint, nil, &out) + return convertRepository(out), res, err +} + +// FindHook returns a repository hook. +func (s *RepositoryService) FindHook(ctx context.Context, repo, id string) (*scm.Hook, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +// FindPerms returns the repository permissions. +func (s *RepositoryService) FindPerms(ctx context.Context, repo string) (*scm.Perm, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +// List returns the profile repository list. +func (s *RepositoryService) List(ctx context.Context, opts *scm.ListOptions) ([]*scm.Repository, *scm.Response, error) { + // Todo can we correctly implement this? Is there a reasonable list for this request not tied to a specific project? + return nil, nil, scm.ErrNotSupported +} + +// ListHooks returns a list or repository hooks. +func (s *RepositoryService) ListHooks(ctx context.Context, repo string, opts *scm.ListOptions) ([]*scm.Hook, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +// ListStatus returns a list of commit statuses. +func (s *RepositoryService) ListStatus(ctx context.Context, repo, ref string, opts *scm.ListOptions) ([]*scm.Status, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +// CreateHook creates a new repository webhook. +func (s *RepositoryService) CreateHook(ctx context.Context, repo string, input *scm.HookInput) (*scm.Hook, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +// CreateStatus creates a new commit status. +func (s *RepositoryService) CreateStatus(ctx context.Context, repo, ref string, input *scm.StatusInput) (*scm.Status, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +// CreateDeployStatus creates a new deployment status. +func (s *RepositoryService) CreateDeployStatus(ctx context.Context, repo string, input *scm.DeployStatus) (*scm.DeployStatus, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +// UpdateHook updates a repository webhook. +func (s *RepositoryService) UpdateHook(ctx context.Context, repo string, input *scm.HookInput) (*scm.Hook, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +// DeleteHook deletes a repository webhook. +func (s *RepositoryService) DeleteHook(ctx context.Context, repo, id string) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +type project struct { + ID string `json:"id"` +} + +type repositories struct { + Count int64 `json:"count"` + Value []*repository `json:"value"` +} + +type repository struct { + DefaultBranch string `json:"defaultBranch"` + ID string `json:"id"` + Name string `json:"name"` + Project struct { + ID string `json:"id"` + Name string `json:"name"` + State string `json:"state"` + URL string `json:"url"` + } `json:"project"` + RemoteURL string `json:"remoteUrl"` + SSHURL string `json:"sshUrl"` + WebURL string `json:"webUrl"` + URL string `json:"url"` +} + +// helper function to convert from the gogs repository list to +// the common repository structure. +func convertRepositoryList(from *repositories, options *scm.ListOptions) []*scm.Repository { + var to []*scm.Repository + + paging := options.Size > 0 + start := uint64(options.Page * options.Size) + end := start + uint64(options.Size) + + var curr uint64 + for _, v := range from.Value { + if !paging || (start <= curr && curr < end) { + to = append(to, convertRepository(v)) + } + curr++ + } + return to +} + +// helper function to convert from the gogs repository structure +// to the common repository structure. +func convertRepository(from *repository) *scm.Repository { + projectURL, err := url.Parse(from.Project.URL) + if err != nil { + panic(fmt.Sprintf("could not parse url for repository's project: %s", err.Error())) + } + + var ns string + + pathSegments := strings.Split(projectURL.Path, "/") + if len(pathSegments) > 1 { + ns = pathSegments[1] + "/" + from.Project.Name + } + + return &scm.Repository{ + ID: from.ID, + FullName: ns + "/" + from.Name, + Name: from.Name, + Namespace: ns, + Link: from.WebURL, + Clone: from.RemoteURL, + CloneSSH: from.SSHURL, + Branch: scm.TrimRef(from.DefaultBranch), + } +} + +func (s *RepositoryService) getProject(ctx context.Context, ro *repoObj) (*project, *scm.Response, error) { + proj := new(project) + projectEndpoint := fmt.Sprintf("%s/_apis/projects/%s?api-version=6.0", ro.org, ro.project) + + res, err := s.client.do(ctx, "GET", projectEndpoint, nil, &proj) + return proj, res, err +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/review.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/review.go new file mode 100644 index 00000000000..38977b4aaa7 --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/review.go @@ -0,0 +1,47 @@ +// 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 azure + +import ( + "context" + + "github.com/jenkins-x/go-scm/scm" +) + +type reviewService struct { + client *wrapper +} + +func (s *reviewService) ListComments(ctx context.Context, s2 string, i, i2 int, options *scm.ListOptions) ([]*scm.ReviewComment, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *reviewService) Update(ctx context.Context, s3 string, i, i2 int, s2 string) (*scm.Review, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *reviewService) Submit(ctx context.Context, s2 string, i, i2 int, input *scm.ReviewSubmitInput) (*scm.Review, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *reviewService) Dismiss(ctx context.Context, s3 string, i, i2 int, s2 string) (*scm.Review, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *reviewService) Find(ctx context.Context, repo string, number, id int) (*scm.Review, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *reviewService) List(ctx context.Context, repo string, number int, opts *scm.ListOptions) ([]*scm.Review, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *reviewService) Create(ctx context.Context, repo string, number int, input *scm.ReviewInput) (*scm.Review, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *reviewService) Delete(ctx context.Context, repo string, number, id int) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/user.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/user.go new file mode 100644 index 00000000000..ac4b28f35f2 --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/user.go @@ -0,0 +1,47 @@ +// 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 azure + +import ( + "context" + + "github.com/jenkins-x/go-scm/scm" +) + +type userService struct { + client *wrapper +} + +func (s *userService) CreateToken(ctx context.Context, s2, s3 string) (*scm.UserToken, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *userService) DeleteToken(ctx context.Context, i int64) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *userService) ListInvitations(ctx context.Context) ([]*scm.Invitation, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *userService) AcceptInvitation(ctx context.Context, i int64) (*scm.Response, error) { + return nil, scm.ErrNotSupported +} + +func (s *userService) Find(ctx context.Context) (*scm.User, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *userService) FindLogin(ctx context.Context, login string) (*scm.User, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} + +func (s *userService) FindEmail(ctx context.Context) (string, *scm.Response, error) { + return "", nil, scm.ErrNotSupported +} + +func (s *userService) ListEmail(context.Context, scm.ListOptions) ([]*scm.Email, *scm.Response, error) { + return nil, nil, scm.ErrNotSupported +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/webhook.go b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/webhook.go new file mode 100644 index 00000000000..d2e6f0daa89 --- /dev/null +++ b/vendor/github.com/jenkins-x/go-scm/scm/driver/azure/webhook.go @@ -0,0 +1,789 @@ +// 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 azure + +import ( + "encoding/json" + "fmt" + "io" + "net/http" + "time" + + "github.com/jenkins-x/go-scm/scm" + "github.com/jenkins-x/go-scm/scm/driver/internal/null" +) + +type webhookService struct { + client *wrapper +} + +func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhook, error) { + data, err := io.ReadAll( + io.LimitReader(req.Body, 10000000), + ) + if err != nil { + return nil, err + } + // we need to read the json data then look at the eventType + var unstructuredJSON map[string]interface{} + jsonErr := json.Unmarshal(data, &unstructuredJSON) + if jsonErr != nil { + return nil, fmt.Errorf("Error parsing JSON from webhook: %s", jsonErr) + } + eventType := unstructuredJSON["eventType"].(string) + + switch eventType { + case "git.push": + // https://docs.microsoft.com/en-us/azure/devops/service-hooks/events?view=azure-devops#git.push + src := new(pushHook) + err := json.Unmarshal(data, src) + if err != nil { + return nil, err + } + dst := convertPushHook(src) + return dst, nil + case "git.pullrequest.created": + // https://docs.microsoft.com/en-us/azure/devops/service-hooks/events?view=azure-devops#git.pullrequest.created + src := new(createPullRequestHook) + err := json.Unmarshal(data, src) + if err != nil { + return nil, err + } + dst := convertCreatePullRequestHook(src) + dst.Action = scm.ActionCreate + return dst, nil + case "git.pullrequest.updated": + // https://docs.microsoft.com/en-us/azure/devops/service-hooks/events?view=azure-devops#git.pullrequest.updated + src := new(updatePullRequestHook) + err := json.Unmarshal(data, src) + if err != nil { + return nil, err + } + dst := convertUpdatePullRequestHook(src) + dst.Action = scm.ActionUpdate + return dst, nil + case "git.pullrequest.merged": + // https://docs.microsoft.com/en-us/azure/devops/service-hooks/events?view=azure-devops#git.pullrequest.merged + src := new(mergePullRequestHook) + err := json.Unmarshal(data, src) + if err != nil { + return nil, err + } + dst := convertMergePullRequestHook(src) + dst.Action = scm.ActionMerge + return dst, nil + case "ms.vss-code.git-pullrequest-comment-event": + src := new(issueCommentPullRequestHook) + err := json.Unmarshal(data, src) + if err != nil { + return nil, err + } + dst := convertIssueCommentHook(src) + dst.Action = getIssueCommentAction(src) + return dst, nil + default: + return nil, scm.ErrUnknownEvent + } +} + +func getIssueCommentAction(src *issueCommentPullRequestHook) scm.Action { + if src.Resource.Comment.IsDeleted { + return scm.ActionDelete + } else if src.Resource.Comment.PublishedDate.Equal(src.Resource.Comment.LastUpdatedDate) { + return scm.ActionCreate + } else { + return scm.ActionEdited + } +} + +func convertPushHook(src *pushHook) *scm.PushHook { + var commits []scm.PushCommit + for i := range src.Resource.Commits { + commits = append(commits, + scm.PushCommit{ + //Sha: c.CommitID, + Message: src.Resource.Commits[i].Comment, + //Link: c.URL, + //Author: scm.Signature{ + // Login: c.Author.Name, + // Email: c.Author.Email, + // Name: c.Author.Name, + // Date: c.Author.Date, + // }, + //Committer: scm.Signature{ + // Login: c.Committer.Name, + // Email: c.Committer.Email, + // Name: c.Committer.Name, + // Date: c.Committer.Date, + // }, + }) + } + dst := &scm.PushHook{ + Commit: scm.Commit{ + Sha: src.Resource.RefUpdates[0].NewObjectID, + Message: "", + Author: scm.Signature{ + Login: src.Resource.PushedBy.ID, + Name: src.Resource.PushedBy.DisplayName, + Email: src.Resource.PushedBy.UniqueName, + Avatar: src.Resource.PushedBy.ImageURL, + }, + Committer: scm.Signature{ + Login: src.Resource.PushedBy.ID, + Name: src.Resource.PushedBy.DisplayName, + Email: src.Resource.PushedBy.UniqueName, + Avatar: src.Resource.PushedBy.ImageURL, + }, + Link: "", + }, + Ref: src.Resource.RefUpdates[0].Name, + Before: src.Resource.RefUpdates[0].OldObjectID, + After: src.Resource.RefUpdates[0].NewObjectID, + Sender: scm.User{ + Login: src.Resource.PushedBy.ID, + Name: src.Resource.PushedBy.DisplayName, + Email: src.Resource.PushedBy.UniqueName, + Avatar: src.Resource.PushedBy.ImageURL, + }, + Repo: scm.Repository{ + ID: src.Resource.Repository.ID, + Branch: scm.TrimRef(src.Resource.Repository.DefaultBranch), + Name: src.Resource.Repository.Name, + Namespace: src.Resource.Repository.Project.Name, + Clone: src.Resource.Repository.RemoteURL, + Link: src.Resource.Repository.RemoteURL, + }, + Commits: commits, + } + return dst +} + +func convertCreatePullRequestHook(src *createPullRequestHook) (returnVal *scm.PullRequestHook) { + returnVal = &scm.PullRequestHook{ + PullRequest: scm.PullRequest{ + Number: src.Resource.PullRequestID, + Title: src.Resource.Title, + Body: src.Resource.Description, + Sha: src.Resource.LastMergeSourceCommit.CommitID, + Ref: src.Resource.SourceRefName, + Source: scm.TrimRef(src.Resource.SourceRefName), + Target: scm.TrimRef(src.Resource.TargetRefName), + Link: src.Resource.URL, + Closed: false, + Merged: false, + Author: scm.User{ + Login: src.Resource.CreatedBy.DisplayName, + Name: src.Resource.CreatedBy.DisplayName, + Email: src.Resource.CreatedBy.UniqueName, + Avatar: src.Resource.CreatedBy.ImageURL, + }, + Created: src.Resource.CreationDate, + }, + Repo: scm.Repository{ + ID: src.Resource.Repository.ID, + Name: src.Resource.Repository.Name, + Namespace: src.Resource.Repository.Project.Name, + Link: src.Resource.Repository.WebURL, + Clone: src.Resource.Repository.WebURL, + CloneSSH: src.Resource.Repository.SSHURL, + }, + Sender: scm.User{ + Login: src.Resource.CreatedBy.ID, + Name: src.Resource.CreatedBy.DisplayName, + Email: src.Resource.CreatedBy.UniqueName, + Avatar: src.Resource.CreatedBy.ImageURL, + }, + } + return returnVal +} + +func convertUpdatePullRequestHook(src *updatePullRequestHook) (returnVal *scm.PullRequestHook) { + returnVal = &scm.PullRequestHook{ + PullRequest: scm.PullRequest{ + Number: src.Resource.PullRequestID, + Title: src.Resource.Title, + Body: src.Resource.Description, + Sha: src.Resource.LastMergeSourceCommit.CommitID, + Ref: src.Resource.SourceRefName, + Source: scm.TrimRef(src.Resource.SourceRefName), + Target: scm.TrimRef(src.Resource.TargetRefName), + Link: src.Resource.URL, + Closed: src.Resource.ClosedDate.Valid, + Merged: false, + Author: scm.User{ + Login: src.Resource.CreatedBy.DisplayName, + Name: src.Resource.CreatedBy.DisplayName, + Email: src.Resource.CreatedBy.UniqueName, + Avatar: src.Resource.CreatedBy.ImageURL, + }, + Created: src.Resource.CreationDate, + }, + Repo: scm.Repository{ + ID: src.Resource.Repository.ID, + Name: src.Resource.Repository.Name, + Namespace: src.Resource.Repository.Project.Name, + Link: src.Resource.Repository.WebURL, + Clone: src.Resource.Repository.WebURL, + CloneSSH: src.Resource.Repository.SSHURL, + }, + Sender: scm.User{ + Login: src.Resource.CreatedBy.ID, + Name: src.Resource.CreatedBy.DisplayName, + Email: src.Resource.CreatedBy.UniqueName, + Avatar: src.Resource.CreatedBy.ImageURL, + }, + } + return returnVal +} + +func convertMergePullRequestHook(src *mergePullRequestHook) (returnVal *scm.PullRequestHook) { + returnVal = &scm.PullRequestHook{ + PullRequest: scm.PullRequest{ + Number: src.Resource.PullRequestID, + Title: src.Resource.Title, + Body: src.Resource.Description, + Sha: src.Resource.LastMergeSourceCommit.CommitID, + Ref: src.Resource.SourceRefName, + Source: scm.TrimRef(src.Resource.SourceRefName), + Target: scm.TrimRef(src.Resource.TargetRefName), + Link: src.Resource.URL, + Closed: false, + Merged: true, + Author: scm.User{ + Login: src.Resource.CreatedBy.DisplayName, + Name: src.Resource.CreatedBy.DisplayName, + Email: src.Resource.CreatedBy.UniqueName, + Avatar: src.Resource.CreatedBy.ImageURL, + }, + Created: src.Resource.CreationDate, + }, + Repo: scm.Repository{ + ID: src.Resource.Repository.ID, + Name: src.Resource.Repository.Name, + Namespace: src.Resource.Repository.Project.Name, + Link: src.Resource.Repository.WebURL, + Clone: src.Resource.Repository.WebURL, + CloneSSH: src.Resource.Repository.SSHURL, + }, + Sender: scm.User{ + Login: src.Resource.CreatedBy.ID, + Name: src.Resource.CreatedBy.DisplayName, + Email: src.Resource.CreatedBy.UniqueName, + Avatar: src.Resource.CreatedBy.ImageURL, + }, + } + return returnVal +} + +func convertIssueCommentHook(src *issueCommentPullRequestHook) *scm.IssueCommentHook { + dst := &scm.IssueCommentHook{ + Repo: scm.Repository{ + ID: src.Resource.PullRequest.Repository.ID, + Namespace: src.Resource.PullRequest.Repository.Project.Name, + Name: src.Resource.PullRequest.Repository.Name, + Branch: scm.TrimRef(src.Resource.PullRequest.SourceRefName), + Private: false, + Clone: src.Resource.PullRequest.Repository.WebURL, + CloneSSH: src.Resource.PullRequest.Repository.SSHURL, + Link: src.Resource.PullRequest.Repository.WebURL, + }, + Issue: scm.Issue{ + Number: src.Resource.PullRequest.PullRequestID, + Title: src.Resource.PullRequest.Title, + Body: src.Resource.PullRequest.Description, + Link: src.Resource.PullRequest.URL, + Author: scm.User{ + Login: src.Resource.PullRequest.CreatedBy.DisplayName, + Name: src.Resource.PullRequest.CreatedBy.DisplayName, + Email: src.Resource.PullRequest.CreatedBy.UniqueName, + Avatar: src.Resource.PullRequest.CreatedBy.ImageURL, + }, + PullRequest: &scm.PullRequest{ + Number: src.Resource.PullRequest.PullRequestID, + Title: src.Resource.PullRequest.Title, + Body: src.Resource.PullRequest.Description, + Sha: src.Resource.PullRequest.LastMergeSourceCommit.CommitID, + Ref: src.Resource.PullRequest.SourceRefName, + Source: scm.TrimRef(src.Resource.PullRequest.SourceRefName), + Target: scm.TrimRef(src.Resource.PullRequest.TargetRefName), + Link: src.Resource.PullRequest.URL, + Closed: false, + Merged: false, + Author: scm.User{ + Login: src.Resource.PullRequest.CreatedBy.DisplayName, + Name: src.Resource.PullRequest.CreatedBy.DisplayName, + Email: src.Resource.PullRequest.CreatedBy.UniqueName, + Avatar: src.Resource.PullRequest.CreatedBy.ImageURL, + }, + Created: src.Resource.PullRequest.CreationDate, + }, + Created: src.Resource.PullRequest.CreationDate, + }, + Comment: scm.Comment{ + ID: src.Resource.Comment.ID, + Body: src.Resource.Comment.Content, + Author: scm.User{ + Email: src.Resource.Comment.Author.UniqueName, + Login: src.Resource.Comment.Author.ID, + Name: src.Resource.Comment.Author.DisplayName, + }, + Created: src.Resource.Comment.PublishedDate, + Updated: src.Resource.Comment.LastUpdatedDate, + }, + Sender: scm.User{ + Email: src.Resource.Comment.Author.UniqueName, + Login: src.Resource.Comment.Author.ID, + Name: src.Resource.Comment.Author.DisplayName, + }, + } + return dst +} + +type pushHook struct { + CreatedDate string `json:"createdDate"` + DetailedMessage struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"detailedMessage"` + EventType string `json:"eventType"` + ID string `json:"id"` + Message struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"message"` + PublisherID string `json:"publisherId"` + Resource struct { + Commits []struct { + Author struct { + Date time.Time `json:"date"` + Email string `json:"email"` + Name string `json:"name"` + } `json:"author"` + Comment string `json:"comment"` + CommitID string `json:"commitId"` + Committer struct { + Date time.Time `json:"date"` + Email string `json:"email"` + Name string `json:"name"` + } `json:"committer"` + URL string `json:"url"` + } `json:"commits"` + Date string `json:"date"` + PushID int64 `json:"pushId"` + PushedBy struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + UniqueName string `json:"uniqueName"` + ImageURL string `json:"imageUrl"` + } `json:"pushedBy"` + RefUpdates []struct { + Name string `json:"name"` + NewObjectID string `json:"newObjectId"` + OldObjectID string `json:"oldObjectId"` + } `json:"refUpdates"` + Repository struct { + DefaultBranch string `json:"defaultBranch"` + ID string `json:"id"` + Name string `json:"name"` + Project struct { + ID string `json:"id"` + Name string `json:"name"` + State string `json:"state"` + URL string `json:"url"` + } `json:"project"` + RemoteURL string `json:"remoteUrl"` + URL string `json:"url"` + } `json:"repository"` + URL string `json:"url"` + } `json:"resource"` + ResourceContainers struct { + Account struct { + ID string `json:"id"` + } `json:"account"` + Collection struct { + ID string `json:"id"` + } `json:"collection"` + Project struct { + ID string `json:"id"` + } `json:"project"` + } `json:"resourceContainers"` + ResourceVersion string `json:"resourceVersion"` + Scope string `json:"scope"` +} + +type createPullRequestHook struct { + ID string `json:"id"` + EventType string `json:"eventType"` + PublisherID string `json:"publisherId"` + Scope string `json:"scope"` + Message struct { + Text string `json:"text"` + HTML string `json:"html"` + Markdown string `json:"markdown"` + } `json:"message"` + DetailedMessage struct { + Text string `json:"text"` + HTML string `json:"html"` + Markdown string `json:"markdown"` + } `json:"detailedMessage"` + Resource struct { + Repository struct { + ID string `json:"id"` + Name string `json:"name"` + URL string `json:"url"` + WebURL string `json:"webUrl"` + SSHURL string `json:"sshUrl"` + Project struct { + ID string `json:"id"` + Name string `json:"name"` + URL string `json:"url"` + State string `json:"state"` + } `json:"project"` + DefaultBranch string `json:"defaultBranch"` + RemoteURL string `json:"remoteUrl"` + } `json:"repository"` + PullRequestID int `json:"pullRequestId"` + Status string `json:"status"` + CreatedBy struct { + ID string `json:"id"` + DisplayName string `json:"displayName"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + ImageURL string `json:"imageUrl"` + } `json:"createdBy"` + CreationDate time.Time `json:"creationDate"` + Title string `json:"title"` + Description string `json:"description"` + SourceRefName string `json:"sourceRefName"` + TargetRefName string `json:"targetRefName"` + MergeStatus string `json:"mergeStatus"` + MergeID string `json:"mergeId"` + LastMergeSourceCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeSourceCommit"` + LastMergeTargetCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeTargetCommit"` + LastMergeCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeCommit"` + Reviewers []struct { + ReviewerURL interface{} `json:"reviewerUrl"` + Vote int `json:"vote"` + ID string `json:"id"` + DisplayName string `json:"displayName"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + ImageURL string `json:"imageUrl"` + IsContainer bool `json:"isContainer"` + } `json:"reviewers"` + URL string `json:"url"` + } `json:"resource"` + ResourceVersion string `json:"resourceVersion"` + ResourceContainers struct { + Collection struct { + ID string `json:"id"` + } `json:"collection"` + Account struct { + ID string `json:"id"` + } `json:"account"` + Project struct { + ID string `json:"id"` + } `json:"project"` + } `json:"resourceContainers"` + CreatedDate time.Time `json:"createdDate"` +} + +type updatePullRequestHook struct { + CreatedDate string `json:"createdDate"` + DetailedMessage struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"detailedMessage"` + EventType string `json:"eventType"` + ID string `json:"id"` + Message struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"message"` + PublisherID string `json:"publisherId"` + Resource struct { + ClosedDate null.String `json:"closedDate"` + Commits []struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"commits"` + CreatedBy struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + } `json:"createdBy"` + CreationDate time.Time `json:"creationDate"` + Description string `json:"description"` + LastMergeCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeCommit"` + LastMergeSourceCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeSourceCommit"` + LastMergeTargetCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeTargetCommit"` + MergeID string `json:"mergeId"` + MergeStatus string `json:"mergeStatus"` + PullRequestID int `json:"pullRequestId"` + Repository struct { + DefaultBranch string `json:"defaultBranch"` + ID string `json:"id"` + Name string `json:"name"` + Project struct { + ID string `json:"id"` + Name string `json:"name"` + State string `json:"state"` + URL string `json:"url"` + } `json:"project"` + RemoteURL string `json:"remoteUrl"` + URL string `json:"url"` + WebURL string `json:"webUrl"` + SSHURL string `json:"sshUrl"` + } `json:"repository"` + Reviewers []struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + IsContainer bool `json:"isContainer"` + ReviewerURL interface{} `json:"reviewerUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + Vote int64 `json:"vote"` + } `json:"reviewers"` + SourceRefName string `json:"sourceRefName"` + Status string `json:"status"` + TargetRefName string `json:"targetRefName"` + Title string `json:"title"` + URL string `json:"url"` + } `json:"resource"` + ResourceContainers struct { + Account struct { + ID string `json:"id"` + } `json:"account"` + Collection struct { + ID string `json:"id"` + } `json:"collection"` + Project struct { + ID string `json:"id"` + } `json:"project"` + } `json:"resourceContainers"` + ResourceVersion string `json:"resourceVersion"` + Scope string `json:"scope"` +} + +type mergePullRequestHook struct { + CreatedDate string `json:"createdDate"` + DetailedMessage struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"detailedMessage"` + EventType string `json:"eventType"` + ID string `json:"id"` + Message struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"message"` + PublisherID string `json:"publisherId"` + Resource struct { + ClosedDate string `json:"closedDate"` + CreatedBy struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + } `json:"createdBy"` + CreationDate time.Time `json:"creationDate"` + Description string `json:"description"` + LastMergeCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeCommit"` + LastMergeSourceCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeSourceCommit"` + LastMergeTargetCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeTargetCommit"` + MergeID string `json:"mergeId"` + MergeStatus string `json:"mergeStatus"` + PullRequestID int `json:"pullRequestId"` + Repository struct { + DefaultBranch string `json:"defaultBranch"` + ID string `json:"id"` + Name string `json:"name"` + Project struct { + ID string `json:"id"` + Name string `json:"name"` + State string `json:"state"` + URL string `json:"url"` + } `json:"project"` + RemoteURL string `json:"remoteUrl"` + URL string `json:"url"` + WebURL string `json:"webUrl"` + SSHURL string `json:"sshUrl"` + } `json:"repository"` + Reviewers []struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + IsContainer bool `json:"isContainer"` + ReviewerURL interface{} `json:"reviewerUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + Vote int64 `json:"vote"` + } `json:"reviewers"` + SourceRefName string `json:"sourceRefName"` + Status string `json:"status"` + TargetRefName string `json:"targetRefName"` + Title string `json:"title"` + URL string `json:"url"` + } `json:"resource"` + ResourceContainers struct { + Account struct { + ID string `json:"id"` + } `json:"account"` + Collection struct { + ID string `json:"id"` + } `json:"collection"` + Project struct { + ID string `json:"id"` + } `json:"project"` + } `json:"resourceContainers"` + ResourceVersion string `json:"resourceVersion"` + Scope string `json:"scope"` +} + +type issueCommentPullRequestHook struct { + CreatedDate string `json:"createdDate"` + DetailedMessage struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"detailedMessage"` + EventType string `json:"eventType"` + ID string `json:"id"` + Message struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"message"` + PublisherID string `json:"publisherId"` + Resource struct { + PullRequest struct { + CreatedBy struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + } `json:"createdBy"` + CreationDate time.Time `json:"creationDate"` + Description string `json:"description"` + LastMergeCommit struct { + CommitID string `json:"commitId"` + Author struct { + Date time.Time `json:"date"` + Email string `json:"email"` + Name string `json:"name"` + } `json:"author"` + URL string `json:"url"` + } `json:"lastMergeCommit"` + LastMergeSourceCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeSourceCommit"` + LastMergeTargetCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeTargetCommit"` + MergeID string `json:"mergeId"` + MergeStatus string `json:"mergeStatus"` + PullRequestID int `json:"pullRequestId"` + Repository struct { + ID string `json:"id"` + Name string `json:"name"` + Project struct { + ID string `json:"id"` + Name string `json:"name"` + State string `json:"state"` + URL string `json:"url"` + } `json:"project"` + RemoteURL string `json:"remoteUrl"` + URL string `json:"url"` + WebURL string `json:"webUrl"` + SSHURL string `json:"sshUrl"` + } `json:"repository"` + Reviewers []struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + IsContainer bool `json:"isContainer"` + ReviewerURL interface{} `json:"reviewerUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + Vote int64 `json:"vote"` + } `json:"reviewers"` + SourceRefName string `json:"sourceRefName"` + Status string `json:"status"` + TargetRefName string `json:"targetRefName"` + Title string `json:"title"` + URL string `json:"url"` + } `json:"pullRequest"` + Comment struct { + ID int `json:"id"` + ParentCommentID int `json:"parentCommentId"` + Content string `json:"content"` + PublishedDate time.Time `json:"publishedDate"` + LastUpdatedDate time.Time `json:"lastUpdatedDate"` + LastContentUpdatedDate time.Time `json:"lastContentUpdatedDate"` + CommentType string `json:"commentType"` + IsDeleted bool `json:"isDeleted"` + Author struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + } `json:"author"` + } `json:"comment"` + } `json:"resource"` + ResourceContainers struct { + Account struct { + ID string `json:"id"` + } `json:"account"` + Collection struct { + ID string `json:"id"` + } `json:"collection"` + Project struct { + ID string `json:"id"` + } `json:"project"` + } `json:"resourceContainers"` + ResourceVersion string `json:"resourceVersion"` + Scope string `json:"scope"` +} diff --git a/vendor/github.com/jenkins-x/go-scm/scm/factory/factory.go b/vendor/github.com/jenkins-x/go-scm/scm/factory/factory.go index 01fe0510738..aa8fc323fe8 100644 --- a/vendor/github.com/jenkins-x/go-scm/scm/factory/factory.go +++ b/vendor/github.com/jenkins-x/go-scm/scm/factory/factory.go @@ -2,12 +2,14 @@ package factory import ( "context" + "encoding/base64" "fmt" "net/http" "net/url" "os" "strings" + "github.com/jenkins-x/go-scm/scm/driver/azure" "github.com/pkg/errors" "github.com/jenkins-x/go-scm/scm" @@ -90,6 +92,8 @@ func newClient(driver, serverURL string, authOptions *AuthOptions, opts ...Clien var err error switch driver { + case "azure": + client = azure.NewDefault() case "bitbucket", "bitbucketcloud": if serverURL != "" { client, err = bitbucket.New(ensureBBCEndpoint(serverURL)) @@ -133,6 +137,15 @@ func newClient(driver, serverURL string, authOptions *AuthOptions, opts ...Clien } if oauthToken != "" { switch driver { + case "azure": + client.Client = &http.Client{ + Transport: &transport.Custom{ + Before: func(r *http.Request) { + encoded := base64.StdEncoding.EncodeToString([]byte(":" + oauthToken)) + r.Header.Set("Authorization", fmt.Sprintf("Basic %s", encoded)) + }, + }, + } case "gitea": client.Client = &http.Client{ Transport: &transport.Authorization{ diff --git a/vendor/modules.txt b/vendor/modules.txt index 1506fb7b85a..373f9d2a1a4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -599,10 +599,11 @@ github.com/jbenet/go-context/io # github.com/jellydator/ttlcache/v2 v2.11.1 ## explicit; go 1.15 github.com/jellydator/ttlcache/v2 -# github.com/jenkins-x/go-scm v1.13.1 +# github.com/jenkins-x/go-scm v1.13.2 ## explicit; go 1.19 github.com/jenkins-x/go-scm/pkg/hmac github.com/jenkins-x/go-scm/scm +github.com/jenkins-x/go-scm/scm/driver/azure github.com/jenkins-x/go-scm/scm/driver/bitbucket github.com/jenkins-x/go-scm/scm/driver/fake github.com/jenkins-x/go-scm/scm/driver/gitea