aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
Diffstat (limited to 'bridge')
-rw-r--r--bridge/bridges.go9
-rw-r--r--bridge/core/bridge.go31
-rw-r--r--bridge/github/config.go2
3 files changed, 25 insertions, 17 deletions
diff --git a/bridge/bridges.go b/bridge/bridges.go
index bfd51cb4..2fcb13d3 100644
--- a/bridge/bridges.go
+++ b/bridge/bridges.go
@@ -3,6 +3,7 @@ package bridge
import (
"github.com/MichaelMure/git-bug/bridge/core"
_ "github.com/MichaelMure/git-bug/bridge/github"
+ "github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/repository"
)
@@ -11,6 +12,14 @@ func Targets() []string {
return core.Targets()
}
+func NewBridge(repo *cache.RepoCache, target string, name string) (*core.Bridge, error) {
+ return core.NewBridge(repo, target, name)
+}
+
func ConfiguredBridges(repo repository.RepoCommon) ([]string, error) {
return core.ConfiguredBridges(repo)
}
+
+func RemoveBridges(repo repository.RepoCommon, fullName string) error {
+ return core.RemoveBridge(repo, fullName)
+}
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go
index 0c83e03e..0eb24c6d 100644
--- a/bridge/core/bridge.go
+++ b/bridge/core/bridge.go
@@ -62,14 +62,14 @@ func NewBridge(repo *cache.RepoCache, target string, name string) (*Bridge, erro
}
func ConfiguredBridges(repo repository.RepoCommon) ([]string, error) {
- configs, err := repo.ReadConfigs("git-bug.")
+ configs, err := repo.ReadConfigs("git-bug.bridge.")
if err != nil {
return nil, errors.Wrap(err, "can't read configured bridges")
}
- re, err := regexp.Compile(`git-bug.([^\.]+\.[^\.]+)`)
+ re, err := regexp.Compile(`git-bug.bridge.([^\.]+\.[^\.]+)`)
if err != nil {
- return nil, err
+ panic(err)
}
set := make(map[string]interface{})
@@ -95,19 +95,18 @@ func ConfiguredBridges(repo repository.RepoCommon) ([]string, error) {
return result, nil
}
-func (b *Bridge) String() string {
- var _type string
- if b.impl.Importer() != nil && b.impl.Exporter() != nil {
- _type = "import/export"
- } else if b.impl.Importer() != nil {
- _type = "import"
- } else if b.impl.Exporter() != nil {
- _type = "export"
- } else {
- panic("bad bridge impl, neither import nor export")
+func RemoveBridge(repo repository.RepoCommon, fullName string) error {
+ re, err := regexp.Compile(`^[^\.]+\.[^\.]+$`)
+ if err != nil {
+ panic(err)
+ }
+
+ if !re.MatchString(fullName) {
+ return fmt.Errorf("bad bridge fullname: %s", fullName)
}
- return fmt.Sprintf("%s.%s: %s", b.impl.Target(), b.Name, _type)
+ keyPrefix := fmt.Sprintf("git-bug.bridge.%s", fullName)
+ return repo.RmConfigs(keyPrefix)
}
func (b *Bridge) Configure() error {
@@ -123,7 +122,7 @@ func (b *Bridge) Configure() error {
func (b *Bridge) storeConfig(conf Configuration) error {
for key, val := range conf {
- storeKey := fmt.Sprintf("git-bug.%s.%s.%s", b.impl.Target(), b.Name, key)
+ storeKey := fmt.Sprintf("git-bug.bridge.%s.%s.%s", b.impl.Target(), b.Name, key)
err := b.repo.StoreConfig(storeKey, val)
if err != nil {
@@ -147,7 +146,7 @@ func (b Bridge) getConfig() (Configuration, error) {
}
func (b Bridge) loadConfig() (Configuration, error) {
- keyPrefix := fmt.Sprintf("git-bug.%s.%s.", b.impl.Target(), b.Name)
+ keyPrefix := fmt.Sprintf("git-bug.bridge.%s.%s.", b.impl.Target(), b.Name)
pairs, err := b.repo.ReadConfigs(keyPrefix)
if err != nil {
diff --git a/bridge/github/config.go b/bridge/github/config.go
index 385630a7..b8531dfe 100644
--- a/bridge/github/config.go
+++ b/bridge/github/config.go
@@ -214,7 +214,7 @@ func promptURL() (string, string, error) {
func splitURL(url string) (string, string, error) {
re, err := regexp.Compile(`github\.com\/([^\/]*)\/([^\/]*)`)
if err != nil {
- return "", "", err
+ panic(err)
}
res := re.FindStringSubmatch(url)