aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/gitlab/config.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-12-10 21:13:54 +0100
committerGitHub <noreply@github.com>2019-12-10 21:13:54 +0100
commite96d8e6771086e20639a16abf6af30f2faa006a0 (patch)
tree606c0d2897c06e4ca226d377917437c62fdd1560 /bridge/gitlab/config.go
parentef6801a37f75fbc5f65b0a5db194b7f88b439e7b (diff)
parentf6b4830c0b68f3b5c616236bc9d51943765c8b4a (diff)
downloadgit-bug-e96d8e6771086e20639a16abf6af30f2faa006a0.tar.gz
Merge pull request #274 from MichaelMure/gitlab-bridge
bridge/gitlab: support self-hosted GitLab instance
Diffstat (limited to 'bridge/gitlab/config.go')
-rw-r--r--bridge/gitlab/config.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go
index 7bc2e577..99c27836 100644
--- a/bridge/gitlab/config.go
+++ b/bridge/gitlab/config.go
@@ -42,6 +42,10 @@ func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor
return nil, fmt.Errorf("you must provide a project URL to configure this bridge with a token")
}
+ if params.URL == "" {
+ params.URL = defaultBaseURL
+ }
+
var url string
// get project url
@@ -56,6 +60,10 @@ func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor
}
}
+ if !strings.HasPrefix(url, params.BaseURL) {
+ return nil, fmt.Errorf("base URL (%s) doesn't match the project URL (%s)", params.BaseURL, url)
+ }
+
user, err := repo.GetUserIdentity()
if err != nil {
return nil, err
@@ -87,13 +95,14 @@ func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor
}
// validate project url and get its ID
- id, err := validateProjectURL(url, token)
+ id, err := validateProjectURL(params.BaseURL, url, token)
if err != nil {
return nil, errors.Wrap(err, "project validation")
}
conf[core.ConfigKeyTarget] = target
conf[keyProjectID] = strconv.Itoa(id)
+ conf[keyGitlabBaseUrl] = params.BaseURL
err = g.ValidateConfig(conf)
if err != nil {
@@ -302,13 +311,16 @@ func getValidGitlabRemoteURLs(remotes map[string]string) []string {
return urls
}
-func validateProjectURL(url string, token *auth.Token) (int, error) {
+func validateProjectURL(baseURL, url string, token *auth.Token) (int, error) {
projectPath, err := getProjectPath(url)
if err != nil {
return 0, err
}
- client := buildClient(token)
+ client, err := buildClient(baseURL, token)
+ if err != nil {
+ return 0, err
+ }
project, _, err := client.Projects.GetProject(projectPath, &gitlab.GetProjectOptions{})
if err != nil {