commands: add "bridge pull"

Michael Muré created

Change summary

bridge/bridges.go             |  8 ++++++
bridge/core/bridge.go         | 41 +++++++++++++++++++++++++++++++++
commands/bridge_pull.go       | 45 +++++++++++++++++++++++++++++++++++++
doc/man/git-bug-bridge-pull.1 | 29 +++++++++++++++++++++++
doc/man/git-bug-bridge.1      |  2 
doc/md/git-bug_bridge.md      |  1 
doc/md/git-bug_bridge_pull.md | 22 ++++++++++++++++++
misc/bash_completion/git-bug  | 21 +++++++++++++++++
misc/zsh_completion/git-bug   | 12 ++++----
9 files changed, 174 insertions(+), 7 deletions(-)

Detailed changes

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)
 }

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 {

commands/bridge_pull.go 🔗

@@ -0,0 +1,45 @@
+package commands
+
+import (
+	"github.com/MichaelMure/git-bug/bridge"
+	"github.com/MichaelMure/git-bug/bridge/core"
+	"github.com/MichaelMure/git-bug/cache"
+	"github.com/spf13/cobra"
+)
+
+func runBridgePull(cmd *cobra.Command, args []string) error {
+	backend, err := cache.NewRepoCache(repo)
+	if err != nil {
+		return err
+	}
+	defer backend.Close()
+
+	var b *core.Bridge
+
+	if len(args) == 0 {
+		b, err = bridge.DefaultBridge(backend)
+	} else {
+		b, err = bridge.NewBridgeFullName(backend, args[0])
+	}
+
+	if err != nil {
+		return err
+	}
+
+	err = b.ImportAll()
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
+var bridgePullCmd = &cobra.Command{
+	Use:   "pull [<name>]",
+	Short: "Pull updates",
+	RunE:  runBridgePull,
+}
+
+func init() {
+	bridgeCmd.AddCommand(bridgePullCmd)
+}

doc/man/git-bug-bridge-pull.1 🔗

@@ -0,0 +1,29 @@
+.TH "GIT-BUG" "1" "Sep 2018" "Generated from git-bug's source code" "" 
+.nh
+.ad l
+
+
+.SH NAME
+.PP
+git\-bug\-bridge\-pull \- Pull updates
+
+
+.SH SYNOPSIS
+.PP
+\fBgit\-bug bridge pull [<name>] [flags]\fP
+
+
+.SH DESCRIPTION
+.PP
+Pull updates
+
+
+.SH OPTIONS
+.PP
+\fB\-h\fP, \fB\-\-help\fP[=false]
+    help for pull
+
+
+.SH SEE ALSO
+.PP
+\fBgit\-bug\-bridge(1)\fP

doc/man/git-bug-bridge.1 🔗

@@ -26,4 +26,4 @@ Configure and use bridges to other bug trackers
 
 .SH SEE ALSO
 .PP
-\fBgit\-bug(1)\fP, \fBgit\-bug\-bridge\-configure(1)\fP, \fBgit\-bug\-bridge\-rm(1)\fP
+\fBgit\-bug(1)\fP, \fBgit\-bug\-bridge\-configure(1)\fP, \fBgit\-bug\-bridge\-pull(1)\fP, \fBgit\-bug\-bridge\-rm(1)\fP

doc/md/git-bug_bridge.md 🔗

@@ -20,5 +20,6 @@ git-bug bridge [flags]
 
 * [git-bug](git-bug.md)	 - A bug tracker embedded in Git
 * [git-bug bridge configure](git-bug_bridge_configure.md)	 - Configure a new bridge
+* [git-bug bridge pull](git-bug_bridge_pull.md)	 - Pull updates
 * [git-bug bridge rm](git-bug_bridge_rm.md)	 - Delete a configured bridge
 

doc/md/git-bug_bridge_pull.md 🔗

@@ -0,0 +1,22 @@
+## git-bug bridge pull
+
+Pull updates
+
+### Synopsis
+
+Pull updates
+
+```
+git-bug bridge pull [<name>] [flags]
+```
+
+### Options
+
+```
+  -h, --help   help for pull
+```
+
+### SEE ALSO
+
+* [git-bug bridge](git-bug_bridge.md)	 - Configure and use bridges to other bug trackers
+

misc/bash_completion/git-bug 🔗

@@ -297,6 +297,26 @@ _git-bug_bridge_configure()
     noun_aliases=()
 }
 
+_git-bug_bridge_pull()
+{
+    last_command="git-bug_bridge_pull"
+
+    command_aliases=()
+
+    commands=()
+
+    flags=()
+    two_word_flags=()
+    local_nonpersistent_flags=()
+    flags_with_completion=()
+    flags_completion=()
+
+
+    must_have_one_flag=()
+    must_have_one_noun=()
+    noun_aliases=()
+}
+
 _git-bug_bridge_rm()
 {
     last_command="git-bug_bridge_rm"
@@ -325,6 +345,7 @@ _git-bug_bridge()
 
     commands=()
     commands+=("configure")
+    commands+=("pull")
     commands+=("rm")
 
     flags=()

misc/zsh_completion/git-bug 🔗

@@ -17,12 +17,6 @@ case $state in
   ;;
   level2)
     case $words[2] in
-      title)
-        _arguments '2: :(edit)'
-      ;;
-      bridge)
-        _arguments '2: :(configure rm)'
-      ;;
       comment)
         _arguments '2: :(add)'
       ;;
@@ -32,6 +26,12 @@ case $state in
       status)
         _arguments '2: :(close open)'
       ;;
+      title)
+        _arguments '2: :(edit)'
+      ;;
+      bridge)
+        _arguments '2: :(configure pull rm)'
+      ;;
       *)
         _arguments '*: :_files'
       ;;