2019-06-09 00:14:35 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-08-13 20:51:14 +03:00
|
|
|
"context"
|
2019-06-25 02:33:48 +03:00
|
|
|
"fmt"
|
2019-08-13 20:51:14 +03:00
|
|
|
"os"
|
|
|
|
"sync"
|
2019-06-09 00:14:35 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/MichaelMure/git-bug/bridge"
|
|
|
|
"github.com/MichaelMure/git-bug/bridge/core"
|
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
|
|
|
"github.com/MichaelMure/git-bug/util/interrupt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func runBridgePush(cmd *cobra.Command, args []string) error {
|
|
|
|
backend, err := cache.NewRepoCache(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer backend.Close()
|
|
|
|
interrupt.RegisterCleaner(backend.Close)
|
|
|
|
|
|
|
|
var b *core.Bridge
|
|
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
b, err = bridge.DefaultBridge(backend)
|
|
|
|
} else {
|
2019-06-21 01:09:20 +03:00
|
|
|
b, err = bridge.LoadBridge(backend, args[0])
|
2019-06-09 00:14:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-08-13 20:51:14 +03:00
|
|
|
parentCtx := context.Background()
|
|
|
|
ctx, cancel := context.WithCancel(parentCtx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
done := make(chan struct{}, 1)
|
|
|
|
|
|
|
|
var mu sync.Mutex
|
|
|
|
interruptCount := 0
|
|
|
|
interrupt.RegisterCleaner(func() error {
|
|
|
|
mu.Lock()
|
|
|
|
if interruptCount > 0 {
|
|
|
|
fmt.Println("Received another interrupt before graceful stop, terminating...")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
interruptCount++
|
|
|
|
mu.Unlock()
|
|
|
|
|
|
|
|
fmt.Println("Received interrupt signal, stopping the import...\n(Hit ctrl-c again to kill the process.)")
|
|
|
|
|
|
|
|
// send signal to stop the importer
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
// block until importer gracefully shutdown
|
|
|
|
<-done
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2019-11-26 22:46:00 +03:00
|
|
|
events, err := b.ExportAll(ctx, time.Time{})
|
2019-06-09 00:14:35 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-26 22:46:00 +03:00
|
|
|
exportedIssues := 0
|
|
|
|
for result := range events {
|
|
|
|
if result.Event != core.ExportEventNothing {
|
|
|
|
fmt.Println(result.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
switch result.Event {
|
|
|
|
case core.ExportEventBug:
|
|
|
|
exportedIssues++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("exported %d issues with %s bridge\n", exportedIssues, b.Name)
|
|
|
|
|
2019-08-13 20:51:14 +03:00
|
|
|
// send done signal
|
|
|
|
close(done)
|
2019-06-09 00:14:35 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var bridgePushCmd = &cobra.Command{
|
|
|
|
Use: "push [<name>]",
|
|
|
|
Short: "Push updates.",
|
2019-12-08 23:15:06 +03:00
|
|
|
PreRunE: loadRepoEnsureUser,
|
2019-06-09 00:14:35 +03:00
|
|
|
RunE: runBridgePush,
|
|
|
|
Args: cobra.MaximumNArgs(1),
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
bridgeCmd.AddCommand(bridgePushCmd)
|
|
|
|
}
|