aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/gitlab
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-23 19:20:45 +0100
committerGitHub <noreply@github.com>2020-02-23 19:20:45 +0100
commit8ef6438fb476e9d510a39ead321cbeee6288e2d2 (patch)
tree2bcd2a5420bbdbed13b3de82992c30b7d17893e2 /bridge/gitlab
parent0e68c10ffc3f9e72e32b8cdfcd917b3fe1ab240c (diff)
parent0cebe1e57e7e4b03aef77cd11bd4fc683c32afc6 (diff)
downloadgit-bug-8ef6438fb476e9d510a39ead321cbeee6288e2d2.tar.gz
Merge pull request #341 from MichaelMure/bridges-default-login
bridge: record the login used during the configure and use it as default credential
Diffstat (limited to 'bridge/gitlab')
-rw-r--r--bridge/gitlab/config.go8
-rw-r--r--bridge/gitlab/export_test.go2
-rw-r--r--bridge/gitlab/gitlab.go1
-rw-r--r--bridge/gitlab/import.go3
-rw-r--r--bridge/gitlab/import_test.go1
5 files changed, 12 insertions, 3 deletions
diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go
index d5dc418c..8d2490b8 100644
--- a/bridge/gitlab/config.go
+++ b/bridge/gitlab/config.go
@@ -117,6 +117,7 @@ func (g *Gitlab) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor
conf[core.ConfigKeyTarget] = target
conf[confKeyProjectID] = strconv.Itoa(id)
conf[confKeyGitlabBaseUrl] = baseUrl
+ conf[confKeyDefaultLogin] = login
err = g.ValidateConfig(conf)
if err != nil {
@@ -146,6 +147,9 @@ func (g *Gitlab) ValidateConfig(conf core.Configuration) error {
if _, ok := conf[confKeyProjectID]; !ok {
return fmt.Errorf("missing %s key", confKeyProjectID)
}
+ if _, ok := conf[confKeyDefaultLogin]; !ok {
+ return fmt.Errorf("missing %s key", confKeyDefaultLogin)
+ }
return nil
}
@@ -246,12 +250,12 @@ func getValidGitlabRemoteURLs(repo repository.RepoCommon, baseUrl string) ([]str
urls := make([]string, 0, len(remotes))
for _, u := range remotes {
- path, err := getProjectPath(baseUrl, u)
+ p, err := getProjectPath(baseUrl, u)
if err != nil {
continue
}
- urls = append(urls, fmt.Sprintf("%s/%s", baseUrl, path))
+ urls = append(urls, fmt.Sprintf("%s/%s", baseUrl, p))
}
return urls, nil
diff --git a/bridge/gitlab/export_test.go b/bridge/gitlab/export_test.go
index d704ac3b..d8966163 100644
--- a/bridge/gitlab/export_test.go
+++ b/bridge/gitlab/export_test.go
@@ -198,6 +198,7 @@ func TestPushPull(t *testing.T) {
err = exporter.Init(ctx, backend, core.Configuration{
confKeyProjectID: strconv.Itoa(projectID),
confKeyGitlabBaseUrl: defaultBaseURL,
+ confKeyDefaultLogin: login,
})
require.NoError(t, err)
@@ -225,6 +226,7 @@ func TestPushPull(t *testing.T) {
err = importer.Init(ctx, backend, core.Configuration{
confKeyProjectID: strconv.Itoa(projectID),
confKeyGitlabBaseUrl: defaultBaseURL,
+ confKeyDefaultLogin: login,
})
require.NoError(t, err)
diff --git a/bridge/gitlab/gitlab.go b/bridge/gitlab/gitlab.go
index ec7b7e57..d854f2f1 100644
--- a/bridge/gitlab/gitlab.go
+++ b/bridge/gitlab/gitlab.go
@@ -21,6 +21,7 @@ const (
confKeyProjectID = "project-id"
confKeyGitlabBaseUrl = "base-url"
+ confKeyDefaultLogin = "default-login"
defaultBaseURL = "https://gitlab.com/"
defaultTimeout = 60 * time.Second
diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go
index 5faf5c48..9ebb0d88 100644
--- a/bridge/gitlab/import.go
+++ b/bridge/gitlab/import.go
@@ -20,7 +20,7 @@ import (
type gitlabImporter struct {
conf core.Configuration
- // default user client
+ // default client
client *gitlab.Client
// iterator
@@ -37,6 +37,7 @@ func (gi *gitlabImporter) Init(_ context.Context, repo *cache.RepoCache, conf co
auth.WithTarget(target),
auth.WithKind(auth.KindToken),
auth.WithMeta(auth.MetaKeyBaseURL, conf[confKeyGitlabBaseUrl]),
+ auth.WithMeta(auth.MetaKeyLogin, conf[confKeyDefaultLogin]),
)
if err != nil {
return err
diff --git a/bridge/gitlab/import_test.go b/bridge/gitlab/import_test.go
index ea7acc18..f916d20c 100644
--- a/bridge/gitlab/import_test.go
+++ b/bridge/gitlab/import_test.go
@@ -110,6 +110,7 @@ func TestImport(t *testing.T) {
err = importer.Init(ctx, backend, core.Configuration{
confKeyProjectID: projectID,
confKeyGitlabBaseUrl: defaultBaseURL,
+ confKeyDefaultLogin: login,
})
require.NoError(t, err)