From 61498f1f26a8303c75d92017c48db6a2a670f38b Mon Sep 17 00:00:00 2001 From: Bill ONeill Date: Sat, 7 Dec 2024 23:29:45 -0500 Subject: [PATCH 1/2] feat: support both https and ssh cloning --- cmd/init.go | 7 +++++++ docs/mp_init.md | 5 +++-- initialize/initialize.go | 28 ++++++++++++++++++++++++++-- lib/provider.go | 1 + 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index 3fc3e0c..531246f 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -89,6 +89,10 @@ See https://docs.gitlab.com/ee/user/search/advanced_search_syntax.html for more query = args[0] } + if initCloneType != "ssh" && initCloneType != "https" { + log.Fatalf("clone-type must be 'ssh' or 'https' but was %s", initCloneType) + } + output, err := initialize.Initialize(initialize.Input{ AllRepos: initAllrepos, Query: query, @@ -98,6 +102,7 @@ See https://docs.gitlab.com/ee/user/search/advanced_search_syntax.html for more ProviderURL: initProviderURL, ReposFromFile: initFlagReposFile, RepoSearch: initRepoSearch, + CloneType: initCloneType, }) if err != nil { log.Fatal(err) @@ -119,6 +124,7 @@ var initRepoSearch bool var initAllrepos bool var initProvider string var initProviderURL string +var initCloneType string func init() { initCmd.Flags().StringVarP(&initFlagReposFile, "file", "f", "", "get repos from a file instead of searching") @@ -126,4 +132,5 @@ func init() { initCmd.Flags().BoolVar(&initAllrepos, "all-repos", false, "get all repos for a given org") initCmd.Flags().StringVar(&initProvider, "provider", "github", "'github' or 'gitlab'") initCmd.Flags().StringVar(&initProviderURL, "provider-url", "", "custom URL for enterprise setups") + initCmd.Flags().StringVar(&initCloneType, "clone-type", "ssh", "'ssh' or 'https'") } diff --git a/docs/mp_init.md b/docs/mp_init.md index 1c4186a..ed8819c 100644 --- a/docs/mp_init.md +++ b/docs/mp_init.md @@ -14,8 +14,8 @@ $ mp init -f repos.txt where repos.txt has lines like: - clever/repo2 - clever/repo2 + clever/repo2 + clever/repo2 ## (2) Init via Search @@ -73,6 +73,7 @@ mp init [query] [flags] ``` --all-repos get all repos for a given org + --clone-type string 'ssh' or 'https' (default "ssh") -f, --file string get repos from a file instead of searching -h, --help help for init --provider string 'github' or 'gitlab' (default "github") diff --git a/initialize/initialize.go b/initialize/initialize.go index d7c4db4..9bbfb30 100644 --- a/initialize/initialize.go +++ b/initialize/initialize.go @@ -24,6 +24,7 @@ type Input struct { ProviderURL string ReposFromFile string RepoSearch bool + CloneType string } // Output for Initialize @@ -44,6 +45,7 @@ func Initialize(input Input) (Output, error) { p := lib.NewProviderFromConfig(lib.ProviderConfig{ Backend: input.Provider, BackendURL: input.ProviderURL, + CloneType: input.CloneType, }) var repos []lib.Repo @@ -264,9 +266,17 @@ func githubAllRepoSearch(p *lib.Provider, query string) ([]lib.Repo, error) { func getFormattedRepos(p *lib.Provider, allRepos map[string]*github.Repository) []lib.Repo { formattedRepos := []lib.Repo{} for _, r := range allRepos { + var url string + if p.ProviderConfig.CloneType == "ssh" { + url = r.GetSSHURL() + } else if p.ProviderConfig.CloneType == "https" { + url = r.GetCloneURL() + } + formattedRepos = append(formattedRepos, lib.Repo{ Name: r.GetName(), Owner: r.Owner.GetLogin(), + CloneURL: url, ProviderConfig: p.ProviderConfig, }) } @@ -310,10 +320,17 @@ func gitlabSearch(p *lib.Provider, query string) ([]lib.Repo, error) { fmt.Println(err) } if _, ok := repoNames[project.Name]; !ok { + var url string + if p.ProviderConfig.CloneType == "ssh" { + url = project.SSHURLToRepo + } else if p.ProviderConfig.CloneType == "https" { + url = project.HTTPURLToRepo + } + repos = append(repos, lib.Repo{ Name: project.Name, Owner: project.Namespace.FullPath, - CloneURL: project.SSHURLToRepo, + CloneURL: url, ProviderConfig: p.ProviderConfig, }) repoNames[project.Name] = true @@ -332,10 +349,17 @@ func gitlabSearch(p *lib.Provider, query string) ([]lib.Repo, error) { } for _, project := range projects { if _, ok := repoNames[project.Name]; !ok { + var url string + if p.ProviderConfig.CloneType == "ssh" { + url = project.SSHURLToRepo + } else if p.ProviderConfig.CloneType == "https" { + url = project.HTTPURLToRepo + } + repos = append(repos, lib.Repo{ Name: project.Name, Owner: project.Namespace.FullPath, - CloneURL: project.SSHURLToRepo, + CloneURL: url, ProviderConfig: p.ProviderConfig, }) repoNames[project.Name] = true diff --git a/lib/provider.go b/lib/provider.go index 7862e72..397f0b5 100644 --- a/lib/provider.go +++ b/lib/provider.go @@ -14,6 +14,7 @@ import ( type ProviderConfig struct { Backend string BackendURL string + CloneType string } func (pc ProviderConfig) IsEnterprise() bool { From bd5e00fee0cfd23ac053eba9d712d8c836786633 Mon Sep 17 00:00:00 2001 From: Bill ONeill Date: Sat, 7 Dec 2024 23:39:04 -0500 Subject: [PATCH 2/2] docs: Update link to homebrew formula --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4aeecc..7bf6132 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Here are several ways to install microplane: - *Pre-built release* - You can download a pre-built version of Microplane from the [Github releases](https://github.com/Clever/microplane/releases). - *Compile it yourself* - Run `go install github.com/Clever/microplane@latest`. In this case the binary will be installed to `$GOPATH/bin/microplane`. Alternately, you can follow the steps under "Development", below. -- *Homebrew* - `brew install microplane`. The latest homebrew formula is [here](https://github.com/Homebrew/homebrew-core/blob/master/Formula/microplane.rb) +- *Homebrew* - `brew install microplane`. The latest homebrew formula is [here](https://github.com/Homebrew/homebrew-core/blob/master/Formula/m/microplane.rb) ## Usage