From df72152d49d4b675f55ccbc586329cb204b5c018 Mon Sep 17 00:00:00 2001 From: omri assa Date: Mon, 5 Aug 2024 00:36:39 +0300 Subject: [PATCH] fix: added some validations and docs --- docs/configuration/environment_variables.md | 2 +- pkg/conf/git_provider.go | 2 +- pkg/git_provider/gitlab.go | 2 ++ pkg/git_provider/gitlab_utils.go | 8 ++++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/configuration/environment_variables.md b/docs/configuration/environment_variables.md index 6056a55..eb4c0d3 100644 --- a/docs/configuration/environment_variables.md +++ b/docs/configuration/environment_variables.md @@ -12,7 +12,7 @@ The helm chart populate them using [values.yaml](https://github.com/quickube/pip The git token that will be used. - GIT_URL - the git url that will be used, mostly relevant when running gitlab on-prem + the git url that will be used, only relevant when running gitlab self hosted - GIT_ORG_NAME The organization name. diff --git a/pkg/conf/git_provider.go b/pkg/conf/git_provider.go index 16bb76c..5bf3d9a 100644 --- a/pkg/conf/git_provider.go +++ b/pkg/conf/git_provider.go @@ -9,7 +9,7 @@ import ( type GitProviderConfig struct { Provider string `envconfig:"GIT_PROVIDER" required:"true"` Token string `envconfig:"GIT_TOKEN" required:"true"` - Url string `envconfig:"GIT_URL" required:"true"` + Url string `envconfig:"GIT_URL" required:"false"` OrgName string `envconfig:"GIT_ORG_NAME" required:"true"` OrgLevelWebhook bool `envconfig:"GIT_ORG_LEVEL_WEBHOOK" default:"false" required:"false"` RepoList string `envconfig:"GIT_WEBHOOK_REPO_LIST" required:"false"` diff --git a/pkg/git_provider/gitlab.go b/pkg/git_provider/gitlab.go index 50a0b7a..f67b259 100644 --- a/pkg/git_provider/gitlab.go +++ b/pkg/git_provider/gitlab.go @@ -41,6 +41,8 @@ func NewGitlabClient(cfg *conf.GlobalConfig) (Client, error) { return nil, fmt.Errorf("failed to get organization data %s", resp.Status) } + cfg = EnsureGitlabURL(cfg) + c := &GitlabClientImpl{ client: client, cfg: cfg, diff --git a/pkg/git_provider/gitlab_utils.go b/pkg/git_provider/gitlab_utils.go index bdcf9da..7b9e433 100644 --- a/pkg/git_provider/gitlab_utils.go +++ b/pkg/git_provider/gitlab_utils.go @@ -153,4 +153,12 @@ func FixRepoNames(c *GitlabClientImpl) error{ } c.cfg.GitProviderConfig.RepoList = strings.Join(formattedRepos, ",") return nil +} + +func EnsureGitlabURL(c *conf.GlobalConfig) *conf.GlobalConfig{ + saasGitlabUrl := "https://gitlab.com" + if c.Url == "" { + c.Url = saasGitlabUrl + } + return c } \ No newline at end of file