aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/gitlab/config.go
diff options
context:
space:
mode:
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 {