From f6630c39976ed800d7dfabbcb3db70fc3dc7f841 Mon Sep 17 00:00:00 2001 From: Jay Gabriels Date: Mon, 19 Aug 2019 08:31:16 -0700 Subject: [PATCH] add base url option for hosted gitlab --- cmd/clone.go | 11 +++++++++++ cmd/clone_gitlab.go | 13 +++++++++++++ configs/configs.go | 1 + sample-conf.yaml | 5 +++++ 4 files changed, 30 insertions(+) diff --git a/cmd/clone.go b/cmd/clone.go index af3912e..845c2f5 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -23,6 +23,7 @@ var ( bitbucketUsername string namespace string color string + baseURL string args []string ) @@ -38,6 +39,8 @@ func init() { // TODO: make gitlab terminology make sense https://about.gitlab.com/2016/01/27/comparing-terms-gitlab-github-bitbucket/ cloneCmd.Flags().StringVarP(&cloneType, "clone-type", "c", "", "GHORG_CLONE_TYPE - clone target type, user or org (default org)") cloneCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "GHORG_GITLAB_DEFAULT_NAMESPACE - gitlab only: limits clone targets to a specific namespace e.g. --namespace=gitlab-org/security-products") + + cloneCmd.Flags().StringVarP(&baseURL, "base-url", "", "", "change the base url to clone from (currently gitlab only)") } var cloneCmd = &cobra.Command{ @@ -93,6 +96,11 @@ var cloneCmd = &cobra.Command{ os.Setenv("GHORG_SCM_TYPE", scmType) } + if cmd.Flags().Changed("base-url") { + url := cmd.Flag("base-url").Value.String() + os.Setenv("GHORG_SCM_BASE_URL", url) + } + configs.GetOrSetToken() if cmd.Flags().Changed("token") { @@ -329,6 +337,9 @@ func PrintConfigs() { colorlog.PrintInfo("* Protocol : " + os.Getenv("GHORG_CLONE_PROTOCOL")) colorlog.PrintInfo("* Branch : " + os.Getenv("GHORG_BRANCH")) colorlog.PrintInfo("* Location : " + os.Getenv("GHORG_ABSOLUTE_PATH_TO_CLONE_TO")) + if os.Getenv("GHORG_SCM_BASE_URL") != "" { + colorlog.PrintInfo("* Base URL : " + os.Getenv("GHORG_SCM_BASE_URL")) + } colorlog.PrintInfo("*************************************") fmt.Println("") } diff --git a/cmd/clone_gitlab.go b/cmd/clone_gitlab.go index 640e9e3..993e335 100644 --- a/cmd/clone_gitlab.go +++ b/cmd/clone_gitlab.go @@ -12,6 +12,13 @@ import ( func getGitLabOrgCloneUrls() ([]string, error) { cloneUrls := []string{} client := gitlab.NewClient(nil, os.Getenv("GHORG_GITLAB_TOKEN")) + + baseURL := os.Getenv("GHORG_SCM_BASE_URL") + + if baseURL != "" { + client.SetBaseURL(baseURL) + } + namespace := os.Getenv("GHORG_GITLAB_DEFAULT_NAMESPACE") opt := &gitlab.ListGroupProjectsOptions{ @@ -75,6 +82,12 @@ func getGitLabUserCloneUrls() ([]string, error) { cloneUrls := []string{} client := gitlab.NewClient(nil, os.Getenv("GHORG_GITLAB_TOKEN")) + baseURL := os.Getenv("GHORG_SCM_BASE_URL") + + if baseURL != "" { + client.SetBaseURL(baseURL) + } + opt := &gitlab.ListProjectsOptions{ ListOptions: gitlab.ListOptions{ PerPage: 50, diff --git a/configs/configs.go b/configs/configs.go index 725c436..7d1e0bf 100644 --- a/configs/configs.go +++ b/configs/configs.go @@ -72,6 +72,7 @@ func initConfig() { getOrSetDefaults("GHORG_GITLAB_TOKEN") getOrSetDefaults("GHORG_BITBUCKET_USERNAME") getOrSetDefaults("GHORG_BITBUCKET_APP_PASSWORD") + getOrSetDefaults("GHORG_SCM_BASE_URL") } // Load triggers the configs to load first, not sure if this is actually needed diff --git a/sample-conf.yaml b/sample-conf.yaml index 84881c6..0c8dbd9 100644 --- a/sample-conf.yaml +++ b/sample-conf.yaml @@ -29,6 +29,11 @@ GHORG_SCM_TYPE: # flag (--color) GHORG_COLOR: +# Change SCM base url (currently gitlab only) +# default: gitlab.com +# flag (--base-url) +GHORG_SCM_BASE_URL: + # --- GITHUB SPECIFIC --- # Add your GitHub token