aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-24 17:11:50 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-24 17:11:50 +0200
commit2282cbb595ff5cc603d11645ddc833d70de9ad9d (patch)
tree635bfafb7c907d3f510b516773e32ddb44d85287 /bridge
parent061e83d4b4aa66c2691b3699a3e770b2a58d26df (diff)
downloadgit-bug-2282cbb595ff5cc603d11645ddc833d70de9ad9d.tar.gz
commands: add "bridge pull"
Diffstat (limited to 'bridge')
-rw-r--r--bridge/bridges.go8
-rw-r--r--bridge/core/bridge.go41
2 files changed, 49 insertions, 0 deletions
diff --git a/bridge/bridges.go b/bridge/bridges.go
index 2fcb13d3..bfd851aa 100644
--- a/bridge/bridges.go
+++ b/bridge/bridges.go
@@ -16,6 +16,14 @@ func NewBridge(repo *cache.RepoCache, target string, name string) (*core.Bridge,
return core.NewBridge(repo, target, name)
}
+func NewBridgeFullName(repo *cache.RepoCache, fullName string) (*core.Bridge, error) {
+ return core.NewBridgeFullName(repo, fullName)
+}
+
+func DefaultBridge(repo *cache.RepoCache) (*core.Bridge, error) {
+ return core.DefaultBridge(repo)
+}
+
func ConfiguredBridges(repo repository.RepoCommon) ([]string, error) {
return core.ConfiguredBridges(repo)
}
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go
index 0eb24c6d..d9d688ba 100644
--- a/bridge/core/bridge.go
+++ b/bridge/core/bridge.go
@@ -61,6 +61,47 @@ func NewBridge(repo *cache.RepoCache, target string, name string) (*Bridge, erro
return bridge, nil
}
+func NewBridgeFullName(repo *cache.RepoCache, fullName string) (*Bridge, error) {
+ target, name, err := splitFullName(fullName)
+ if err != nil {
+ return nil, err
+ }
+
+ return NewBridge(repo, target, name)
+}
+
+func DefaultBridge(repo *cache.RepoCache) (*Bridge, error) {
+ bridges, err := ConfiguredBridges(repo)
+ if err != nil {
+ return nil, err
+ }
+
+ if len(bridges) == 0 {
+ return nil, fmt.Errorf("no configured bridge")
+ }
+
+ if len(bridges) > 1 {
+ return nil, fmt.Errorf("multiple bridge configured")
+ }
+
+ target, name, err := splitFullName(bridges[0])
+ if err != nil {
+ return nil, err
+ }
+
+ return NewBridge(repo, target, name)
+}
+
+func splitFullName(fullName string) (string, string, error) {
+ split := strings.Split(fullName, ".")
+
+ if len(split) != 2 {
+ return "", "", fmt.Errorf("bad bridge fullname: %s", fullName)
+ }
+
+ return split[0], split[1], nil
+}
+
func ConfiguredBridges(repo repository.RepoCommon) ([]string, error) {
configs, err := repo.ReadConfigs("git-bug.bridge.")
if err != nil {