aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
Diffstat (limited to 'bridge')
-rw-r--r--bridge/bridges.go7
-rw-r--r--bridge/core/bridge.go17
-rw-r--r--bridge/core/interfaces.go5
-rw-r--r--bridge/github/config.go9
-rw-r--r--bridge/github/export.go2
-rw-r--r--bridge/github/export_test.go2
-rw-r--r--bridge/github/github.go21
-rw-r--r--bridge/github/import.go6
-rw-r--r--bridge/github/import_test.go2
-rw-r--r--bridge/gitlab/gitlab.go6
-rw-r--r--bridge/launchpad/config.go7
-rw-r--r--bridge/launchpad/import.go5
-rw-r--r--bridge/launchpad/launchpad.go19
13 files changed, 78 insertions, 30 deletions
diff --git a/bridge/bridges.go b/bridge/bridges.go
index a306fe5d..5d3066f9 100644
--- a/bridge/bridges.go
+++ b/bridge/bridges.go
@@ -21,6 +21,13 @@ func Targets() []string {
return core.Targets()
}
+// LoginMetaKey return the metadata key used to store the remote bug-tracker login
+// on the user identity. The corresponding value is used to match identities and
+// credentials.
+func LoginMetaKey(target string) (string, error) {
+ return core.LoginMetaKey(target)
+}
+
// Instantiate a new Bridge for a repo, from the given target and name
func NewBridge(repo *cache.RepoCache, target string, name string) (*core.Bridge, error) {
return core.NewBridge(repo, target, name)
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go
index 7891763f..ac0d47d7 100644
--- a/bridge/core/bridge.go
+++ b/bridge/core/bridge.go
@@ -28,6 +28,7 @@ const (
)
var bridgeImpl map[string]reflect.Type
+var bridgeLoginMetaKey map[string]string
// BridgeParams holds parameters to simplify the bridge configuration without
// having to make terminal prompts.
@@ -59,7 +60,11 @@ func Register(impl BridgeImpl) {
if bridgeImpl == nil {
bridgeImpl = make(map[string]reflect.Type)
}
+ if bridgeLoginMetaKey == nil {
+ bridgeLoginMetaKey = make(map[string]string)
+ }
bridgeImpl[impl.Target()] = reflect.TypeOf(impl)
+ bridgeLoginMetaKey[impl.Target()] = impl.LoginMetaKey()
}
// Targets return all known bridge implementation target
@@ -81,6 +86,18 @@ func TargetExist(target string) bool {
return ok
}
+// LoginMetaKey return the metadata key used to store the remote bug-tracker login
+// on the user identity. The corresponding value is used to match identities and
+// credentials.
+func LoginMetaKey(target string) (string, error) {
+ metaKey, ok := bridgeLoginMetaKey[target]
+ if !ok {
+ return "", fmt.Errorf("unknown bridge target %v", target)
+ }
+
+ return metaKey, nil
+}
+
// Instantiate a new Bridge for a repo, from the given target and name
func NewBridge(repo *cache.RepoCache, target string, name string) (*Bridge, error) {
implType, ok := bridgeImpl[target]
diff --git a/bridge/core/interfaces.go b/bridge/core/interfaces.go
index 77e0a7b9..ab2f3977 100644
--- a/bridge/core/interfaces.go
+++ b/bridge/core/interfaces.go
@@ -13,6 +13,11 @@ type BridgeImpl interface {
// Target return the target of the bridge (e.g.: "github")
Target() string
+ // LoginMetaKey return the metadata key used to store the remote bug-tracker login
+ // on the user identity. The corresponding value is used to match identities and
+ // credentials.
+ LoginMetaKey() string
+
// Configure handle the user interaction and return a key/value configuration
// for future use
Configure(repo *cache.RepoCache, params BridgeParams) (Configuration, error)
diff --git a/bridge/github/config.go b/bridge/github/config.go
index ed32f398..9477801d 100644
--- a/bridge/github/config.go
+++ b/bridge/github/config.go
@@ -27,15 +27,6 @@ import (
"github.com/MichaelMure/git-bug/util/colors"
)
-const (
- target = "github"
- githubV3Url = "https://api.github.com"
- keyOwner = "owner"
- keyProject = "project"
-
- defaultTimeout = 60 * time.Second
-)
-
var (
ErrBadProjectURL = errors.New("bad project url")
)
diff --git a/bridge/github/export.go b/bridge/github/export.go
index 1e27be4a..c363e188 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -76,7 +76,7 @@ func (ge *githubExporter) Init(repo *cache.RepoCache, conf core.Configuration) e
}
login := user.ImmutableMetadata()[metaKeyGithubLogin]
- creds, err := auth.List(repo, auth.WithMeta(metaKeyGithubLogin, login), auth.WithTarget(target), auth.WithKind(auth.KindToken))
+ creds, err := auth.List(repo, auth.WithMeta(auth.MetaKeyLogin, login), auth.WithTarget(target), auth.WithKind(auth.KindToken))
if err != nil {
return err
}
diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go
index cb6bacc1..89040d8f 100644
--- a/bridge/github/export_test.go
+++ b/bridge/github/export_test.go
@@ -179,7 +179,7 @@ func TestPushPull(t *testing.T) {
})
token := auth.NewToken(envToken, target)
- token.SetMetadata(metaKeyGithubLogin, login)
+ token.SetMetadata(auth.MetaKeyLogin, login)
err = auth.Store(repo, token)
require.NoError(t, err)
diff --git a/bridge/github/github.go b/bridge/github/github.go
index 874c2d11..19dc8a08 100644
--- a/bridge/github/github.go
+++ b/bridge/github/github.go
@@ -3,6 +3,7 @@ package github
import (
"context"
+ "time"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
@@ -11,12 +12,32 @@ import (
"github.com/MichaelMure/git-bug/bridge/core/auth"
)
+const (
+ target = "github"
+
+ metaKeyGithubId = "github-id"
+ metaKeyGithubUrl = "github-url"
+ metaKeyGithubLogin = "github-login"
+
+ keyOwner = "owner"
+ keyProject = "project"
+
+ githubV3Url = "https://api.github.com"
+ defaultTimeout = 60 * time.Second
+)
+
+var _ core.BridgeImpl = &Github{}
+
type Github struct{}
func (*Github) Target() string {
return target
}
+func (g *Github) LoginMetaKey() string {
+ return metaKeyGithubLogin
+}
+
func (*Github) NewImporter() core.Importer {
return &githubImporter{}
}
diff --git a/bridge/github/import.go b/bridge/github/import.go
index f2c9a53d..6a4c0110 100644
--- a/bridge/github/import.go
+++ b/bridge/github/import.go
@@ -15,12 +15,6 @@ import (
"github.com/MichaelMure/git-bug/util/text"
)
-const (
- metaKeyGithubId = "github-id"
- metaKeyGithubUrl = "github-url"
- metaKeyGithubLogin = "github-login"
-)
-
// githubImporter implement the Importer interface
type githubImporter struct {
conf core.Configuration
diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go
index 73eaa096..a8f8e346 100644
--- a/bridge/github/import_test.go
+++ b/bridge/github/import_test.go
@@ -145,7 +145,7 @@ func Test_Importer(t *testing.T) {
author.SetMetadata(metaKeyGithubLogin, login)
token := auth.NewToken(envToken, target)
- token.SetMetadata(metaKeyGithubLogin, login)
+ token.SetMetadata(auth.MetaKeyLogin, login)
err = auth.Store(repo, token)
require.NoError(t, err)
diff --git a/bridge/gitlab/gitlab.go b/bridge/gitlab/gitlab.go
index 9298dc8e..8512379c 100644
--- a/bridge/gitlab/gitlab.go
+++ b/bridge/gitlab/gitlab.go
@@ -26,12 +26,18 @@ const (
defaultTimeout = 60 * time.Second
)
+var _ core.BridgeImpl = &Gitlab{}
+
type Gitlab struct{}
func (*Gitlab) Target() string {
return target
}
+func (g *Gitlab) LoginMetaKey() string {
+ return metaKeyGitlabLogin
+}
+
func (*Gitlab) NewImporter() core.Importer {
return &gitlabImporter{}
}
diff --git a/bridge/launchpad/config.go b/bridge/launchpad/config.go
index 674aff00..e029fad3 100644
--- a/bridge/launchpad/config.go
+++ b/bridge/launchpad/config.go
@@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
"regexp"
- "time"
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/cache"
@@ -14,12 +13,6 @@ import (
var ErrBadProjectURL = errors.New("bad Launchpad project URL")
-const (
- target = "launchpad-preview"
- keyProject = "project"
- defaultTimeout = 60 * time.Second
-)
-
func (l *Launchpad) Configure(repo *cache.RepoCache, params core.BridgeParams) (core.Configuration, error) {
if params.TokenRaw != "" {
fmt.Println("warning: token params are ineffective for a Launchpad bridge")
diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go
index ecbf74f8..5bca8e63 100644
--- a/bridge/launchpad/import.go
+++ b/bridge/launchpad/import.go
@@ -20,11 +20,6 @@ func (li *launchpadImporter) Init(repo *cache.RepoCache, conf core.Configuration
return nil
}
-const (
- metaKeyLaunchpadID = "launchpad-id"
- metaKeyLaunchpadLogin = "launchpad-login"
-)
-
func (li *launchpadImporter) ensurePerson(repo *cache.RepoCache, owner LPPerson) (*cache.IdentityCache, error) {
// Look first in the cache
i, err := repo.ResolveIdentityImmutableMetadata(metaKeyLaunchpadLogin, owner.Login)
diff --git a/bridge/launchpad/launchpad.go b/bridge/launchpad/launchpad.go
index 030d9169..b4fcdd00 100644
--- a/bridge/launchpad/launchpad.go
+++ b/bridge/launchpad/launchpad.go
@@ -2,15 +2,34 @@
package launchpad
import (
+ "time"
+
"github.com/MichaelMure/git-bug/bridge/core"
)
+const (
+ target = "launchpad-preview"
+
+ metaKeyLaunchpadID = "launchpad-id"
+ metaKeyLaunchpadLogin = "launchpad-login"
+
+ keyProject = "project"
+
+ defaultTimeout = 60 * time.Second
+)
+
+var _ core.BridgeImpl = &Launchpad{}
+
type Launchpad struct{}
func (*Launchpad) Target() string {
return "launchpad-preview"
}
+func (l *Launchpad) LoginMetaKey() string {
+ return metaKeyLaunchpadLogin
+}
+
func (*Launchpad) NewImporter() core.Importer {
return &launchpadImporter{}
}