add base url option for hosted gitlab

This commit is contained in:
Jay Gabriels
2019-08-19 08:31:16 -07:00
parent c61f370045
commit f6630c3997
4 changed files with 30 additions and 0 deletions

View File

@@ -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("")
}

View File

@@ -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,

View File

@@ -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

View File

@@ -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