From c8d59edaf07f2cdf68e860dda6eac44a4b5a0cc3 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Fri, 12 Jan 2018 14:51:19 +0000 Subject: [PATCH 1/4] Use 'SetBaseURL' to correctly set GitLab URL based on user params. This change updates server/server.go to set the GitLab URL using the `Client.SetBaseURL` to set the base URL off of the configured param. Previosuly even if a user set the `--gitlab-hostname` the default URL for GitLab would not overriden to match this. Closes #227 --- server/server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/server.go b/server/server.go index 7281c863..3156c02b 100644 --- a/server/server.go +++ b/server/server.go @@ -105,6 +105,7 @@ func NewServer(config Config) (*Server, error) { gitlabClient = &vcs.GitlabClient{ Client: gitlab.NewClient(nil, config.GitlabToken), } + gitlabClient.Client.SetBaseURL(config.GitlabHostname) } var webhooksConfig []webhooks.Config for _, c := range config.Webhooks { From ec000334a976dc9c8688086e15639d763378bde5 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Fri, 12 Jan 2018 15:45:29 +0000 Subject: [PATCH 2/4] Update GitLab SetBaseURL to evaluate response. --- server/server.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/server.go b/server/server.go index 3156c02b..12f16a6a 100644 --- a/server/server.go +++ b/server/server.go @@ -105,7 +105,10 @@ func NewServer(config Config) (*Server, error) { gitlabClient = &vcs.GitlabClient{ Client: gitlab.NewClient(nil, config.GitlabToken), } - gitlabClient.Client.SetBaseURL(config.GitlabHostname) + err := gitlabClient.Client.SetBaseURL(config.GitlabHostname) + if err != nil { + return nil, err + } } var webhooksConfig []webhooks.Config for _, c := range config.Webhooks { From f6a97c3ba96c7033b53a146fc37f45eab31fe975 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Mon, 15 Jan 2018 08:33:54 +0000 Subject: [PATCH 3/4] Feedback based updates to ensure the correct parsing of GitLab URL --- server/server.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/server.go b/server/server.go index 12f16a6a..8e877d85 100644 --- a/server/server.go +++ b/server/server.go @@ -105,8 +105,13 @@ func NewServer(config Config) (*Server, error) { gitlabClient = &vcs.GitlabClient{ Client: gitlab.NewClient(nil, config.GitlabToken), } - err := gitlabClient.Client.SetBaseURL(config.GitlabHostname) + // Ensure the BaseURL has /api/v4/ appended. We only care about the Scheme + // and Host. GH-229 + u, err := url.Parse(config.GitlabHostname) if err != nil { + return nil, errors.Wrap(err, "parsing GitLab hostname") + } + if err := gitlabClient.Client.SetBaseURL(fmt.Sprintf("%s://%s/api/v4/", u.Scheme, u.Host)); err != nil { return nil, err } } From 6d67178f6227f0c001aa976e270229421d134cf2 Mon Sep 17 00:00:00 2001 From: Luke Kysow Date: Mon, 15 Jan 2018 21:44:48 -0800 Subject: [PATCH 4/4] Set GitLab url for on-prem installations --- server/server.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/server/server.go b/server/server.go index 8e877d85..908d1bc5 100644 --- a/server/server.go +++ b/server/server.go @@ -105,14 +105,20 @@ func NewServer(config Config) (*Server, error) { gitlabClient = &vcs.GitlabClient{ Client: gitlab.NewClient(nil, config.GitlabToken), } - // Ensure the BaseURL has /api/v4/ appended. We only care about the Scheme - // and Host. GH-229 - u, err := url.Parse(config.GitlabHostname) - if err != nil { - return nil, errors.Wrap(err, "parsing GitLab hostname") - } - if err := gitlabClient.Client.SetBaseURL(fmt.Sprintf("%s://%s/api/v4/", u.Scheme, u.Host)); err != nil { - return nil, err + // If not using gitlab.com we need to set the URL to the API. + if config.GitlabHostname != "gitlab.com" { + // Check if they've also provided a scheme so we don't prepend it + // again. + scheme := "https" + schemeSplit := strings.Split(config.GitlabHostname, "://") + if len(schemeSplit) > 1 { + scheme = schemeSplit[0] + config.GitlabHostname = schemeSplit[1] + } + apiURL := fmt.Sprintf("%s://%s/api/v4/", scheme, config.GitlabHostname) + if err := gitlabClient.Client.SetBaseURL(apiURL); err != nil { + return nil, errors.Wrapf(err, "setting GitLab API URL: %s", apiURL) + } } } var webhooksConfig []webhooks.Config