aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAmine <hilalyamine@gmail.com>2019-11-03 17:34:51 +0100
committerGitHub <noreply@github.com>2019-11-03 17:34:51 +0100
commit163ea9c93306c387f84ff0b85c2d8fca4c01e449 (patch)
tree05ab55090bf196b940a4f6b0e4aaec9975b997bc /commands
parent16bd116971bb7abc7308e95c474b433512672432 (diff)
parent57e23c8ada0a9d921a6b68187a76eb5c8b8a407d (diff)
downloadgit-bug-163ea9c93306c387f84ff0b85c2d8fca4c01e449.tar.gz
Merge pull request #236 from MichaelMure/import-after
commands: support bridge imports after a given date
Diffstat (limited to 'commands')
-rw-r--r--commands/bridge_pull.go42
-rw-r--r--commands/bridge_push.go17
2 files changed, 39 insertions, 20 deletions
diff --git a/commands/bridge_pull.go b/commands/bridge_pull.go
index 2bdd24c3..67f19024 100644
--- a/commands/bridge_pull.go
+++ b/commands/bridge_pull.go
@@ -7,6 +7,8 @@ import (
"sync"
"time"
+ "github.com/araddon/dateparse"
+ "github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/bridge"
@@ -15,7 +17,16 @@ import (
"github.com/MichaelMure/git-bug/util/interrupt"
)
+var (
+ bridgePullImportSince string
+ bridgePullNoResume bool
+)
+
func runBridgePull(cmd *cobra.Command, args []string) error {
+ if bridgePullNoResume && bridgePullImportSince != "" {
+ return fmt.Errorf("only one of --no-resume and --since flags should be used")
+ }
+
backend, err := cache.NewRepoCache(repo)
if err != nil {
return err
@@ -64,8 +75,20 @@ func runBridgePull(cmd *cobra.Command, args []string) error {
return nil
})
- // TODO: by default import only new events
- events, err := b.ImportAll(ctx, time.Time{})
+ var events <-chan core.ImportResult
+ switch {
+ case bridgePullNoResume:
+ events, err = b.ImportAllSince(ctx, time.Time{})
+ case bridgePullImportSince != "":
+ since, err2 := parseSince(bridgePullImportSince)
+ if err2 != nil {
+ return errors.Wrap(err2, "import time parsing")
+ }
+ events, err = b.ImportAllSince(ctx, since)
+ default:
+ events, err = b.ImportAll(ctx)
+ }
+
if err != nil {
return err
}
@@ -85,14 +108,23 @@ func runBridgePull(cmd *cobra.Command, args []string) error {
}
}
+ fmt.Printf("imported %d issues and %d identities with %s bridge\n", importedIssues, importedIdentities, b.Name)
+
// send done signal
close(done)
- fmt.Printf("Successfully imported %d issues and %d identities with %s bridge\n", importedIssues, importedIdentities, b.Name)
-
return nil
}
+func parseSince(since string) (time.Time, error) {
+ duration, err := time.ParseDuration(since)
+ if err == nil {
+ return time.Now().Add(-duration), nil
+ }
+
+ return dateparse.ParseLocal(since)
+}
+
var bridgePullCmd = &cobra.Command{
Use: "pull [<name>]",
Short: "Pull updates.",
@@ -103,4 +135,6 @@ var bridgePullCmd = &cobra.Command{
func init() {
bridgeCmd.AddCommand(bridgePullCmd)
+ bridgePullCmd.Flags().BoolVarP(&bridgePullNoResume, "no-resume", "n", false, "force importing all bugs")
+ bridgePullCmd.Flags().StringVarP(&bridgePullImportSince, "since", "s", "", "import only bugs updated after the given date (ex: \"200h\" or \"june 2 2019\")")
}
diff --git a/commands/bridge_push.go b/commands/bridge_push.go
index 00413f06..26f42dc4 100644
--- a/commands/bridge_push.go
+++ b/commands/bridge_push.go
@@ -63,28 +63,13 @@ func runBridgePush(cmd *cobra.Command, args []string) error {
return nil
})
- // TODO: by default export only new events
- events, err := b.ExportAll(ctx, time.Time{})
+ err = b.ExportAll(ctx, time.Time{})
if err != nil {
return err
}
- exportedIssues := 0
- for result := range events {
- if result.Event != core.ExportEventNothing {
- fmt.Println(result.String())
- }
-
- switch result.Event {
- case core.ExportEventBug:
- exportedIssues++
- }
- }
-
// send done signal
close(done)
-
- fmt.Printf("Successfully exported %d issues with %s bridge\n", exportedIssues, b.Name)
return nil
}