From 75c70bf804aa9bcd3a641b4f05b675d372be5d40 Mon Sep 17 00:00:00 2001 From: Jacob Cofman Date: Wed, 6 Mar 2019 23:31:15 +0100 Subject: [PATCH 1/2] try this --- gitlab.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gitlab.go b/gitlab.go index c8fb0a59..4a984d18 100644 --- a/gitlab.go +++ b/gitlab.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/xanzy/go-gitlab" "gopkg.in/src-d/go-git.v4" + gitHttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http" "gopkg.in/src-d/go-git.v4/storage/memory" ) @@ -126,6 +127,9 @@ func cloneGitlabRepo(tempDir string, p *gitlab.Project) (*RepoDescriptor, error) repo *git.Repository err error ) + + gitLabToken := os.Getenv("GITLAB_TOKEN") + if opts.ExcludeForks && p.ForkedFromProject != nil { return nil, fmt.Errorf("skipping %s, excluding forks", p.Name) } @@ -140,9 +144,14 @@ func cloneGitlabRepo(tempDir string, p *gitlab.Project) (*RepoDescriptor, error) URL: p.HTTPURLToRepo, } - if sshAuth != nil { + if sshAuth != nil && gitLabToken == "" { opt.URL = p.SSHURLToRepo opt.Auth = sshAuth + } else if gitLabToken != "" { + opt.Auth = &gitHttp.BasicAuth { + Username: "fakeUsername", // yes, this can be anything except an empty string + Password: gitLabToken, + } } log.Infof("cloning: %s", p.Name) From 771055fd59f2a693f8d9f2d56f4c9926e5102079 Mon Sep 17 00:00:00 2001 From: Ixl123 Date: Fri, 8 Mar 2019 14:38:47 +0100 Subject: [PATCH 2/2] add changelog and format go code --- CHANGELOG.md | 3 +++ gitlab.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81f53a55..638a3c71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ CHANGELOG ========= +x.xx.x +--- +- uses the `GITLAB_TOKEN` to clone GitLab repos. 1.24.0 ---- diff --git a/gitlab.go b/gitlab.go index 4a984d18..79b25ca3 100644 --- a/gitlab.go +++ b/gitlab.go @@ -148,7 +148,7 @@ func cloneGitlabRepo(tempDir string, p *gitlab.Project) (*RepoDescriptor, error) opt.URL = p.SSHURLToRepo opt.Auth = sshAuth } else if gitLabToken != "" { - opt.Auth = &gitHttp.BasicAuth { + opt.Auth = &gitHttp.BasicAuth{ Username: "fakeUsername", // yes, this can be anything except an empty string Password: gitLabToken, }