diff options
author | Michael Muré <batolettre@gmail.com> | 2019-11-03 16:46:51 +0100 |
---|---|---|
committer | amine <hilalyamine@gmail.com> | 2019-11-03 17:23:05 +0100 |
commit | 57e23c8ada0a9d921a6b68187a76eb5c8b8a407d (patch) | |
tree | 05ab55090bf196b940a4f6b0e4aaec9975b997bc /commands/bridge_pull.go | |
parent | 614bc5a2c53409a8e9c85ab31a104428069aa7b3 (diff) | |
download | git-bug-57e23c8ada0a9d921a6b68187a76eb5c8b8a407d.tar.gz |
bridge: improvement on the import resume feature
Diffstat (limited to 'commands/bridge_pull.go')
-rw-r--r-- | commands/bridge_pull.go | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/commands/bridge_pull.go b/commands/bridge_pull.go index 2ba11209..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" @@ -16,12 +18,12 @@ import ( ) var ( - importSince int64 - noResume bool + bridgePullImportSince string + bridgePullNoResume bool ) func runBridgePull(cmd *cobra.Command, args []string) error { - if noResume && importSince != 0 { + if bridgePullNoResume && bridgePullImportSince != "" { return fmt.Errorf("only one of --no-resume and --since flags should be used") } @@ -74,18 +76,21 @@ func runBridgePull(cmd *cobra.Command, args []string) error { }) var events <-chan core.ImportResult - if noResume { - events, err = b.ImportAll(ctx) - } else { - var since time.Time - if importSince != 0 { - since = time.Unix(importSince, 0) + 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) - if err != nil { - return err - } + default: + events, err = b.ImportAll(ctx) + } + + if err != nil { + return err } importedIssues := 0 @@ -108,7 +113,16 @@ func runBridgePull(cmd *cobra.Command, args []string) error { // send done signal close(done) - return err + 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{ @@ -121,6 +135,6 @@ var bridgePullCmd = &cobra.Command{ func init() { bridgeCmd.AddCommand(bridgePullCmd) - bridgePullCmd.Flags().BoolVarP(&noResume, "no-resume", "n", false, "force importing all bugs") - bridgePullCmd.Flags().Int64VarP(&importSince, "since", "s", 0, "import only bugs updated after the given date (must be a unix timestamp)") + 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\")") } |