diff options
author | amine <hilalyamine@gmail.com> | 2019-12-10 20:30:29 +0100 |
---|---|---|
committer | amine <hilalyamine@gmail.com> | 2019-12-10 21:05:55 +0100 |
commit | f6b4830c0b68f3b5c616236bc9d51943765c8b4a (patch) | |
tree | 324f36a49d1a26253bb1fc1ecc923d50aaed2912 /bridge/gitlab/config.go | |
parent | f1ed857cbd3a253d77b31c0c896fdc4ade40844f (diff) | |
download | git-bug-f6b4830c0b68f3b5c616236bc9d51943765c8b4a.tar.gz git-bug-f6b4830c0b68f3b5c616236bc9d51943765c8b4a.zip |
bridge/gitlab: support self-hosted GitLab instance
Diffstat (limited to 'bridge/gitlab/config.go')
-rw-r--r-- | bridge/gitlab/config.go | 18 |
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 { |