aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/gitlab
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-23 14:05:03 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-23 14:20:54 +0100
commit0cebe1e57e7e4b03aef77cd11bd4fc683c32afc6 (patch)
tree6c488eef7d39ffcf9226cb1952460b44920ed39e /bridge/gitlab
parentb3318335986618388637a9d35d68b39633e4548a (diff)
downloadgit-bug-0cebe1e57e7e4b03aef77cd11bd4fc683c32afc6.tar.gz
bridge: record the login used during the configure and use it as default credential
fix #338
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 b730a365..7d0e9a2f 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
}
@@ -249,12 +253,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)