bridge: move export event handling to the CLI

This commit is contained in:
Michael Muré 2019-11-26 20:46:00 +01:00
parent 4f856d6f78
commit 1a1e313f30
2 changed files with 20 additions and 24 deletions

View File

@ -365,39 +365,21 @@ func (b *Bridge) ImportAll(ctx context.Context) (<-chan ImportResult, error) {
return b.ImportAllSince(ctx, time.Time{})
}
func (b *Bridge) ExportAll(ctx context.Context, since time.Time) error {
func (b *Bridge) ExportAll(ctx context.Context, since time.Time) (<-chan ExportResult, error) {
exporter := b.getExporter()
if exporter == nil {
return ErrExportNotSupported
return nil, ErrExportNotSupported
}
err := b.ensureConfig()
if err != nil {
return err
return nil, err
}
err = b.ensureInit()
if err != nil {
return err
return nil, err
}
events, err := exporter.ExportAll(ctx, b.repo, since)
if err != nil {
return err
}
exportedIssues := 0
for result := range events {
if result.Event != ExportEventNothing {
fmt.Println(result.String())
}
switch result.Event {
case ExportEventBug:
exportedIssues++
}
}
fmt.Printf("exported %d issues with %s bridge\n", exportedIssues, b.Name)
return nil
return exporter.ExportAll(ctx, b.repo, since)
}

View File

@ -63,11 +63,25 @@ func runBridgePush(cmd *cobra.Command, args []string) error {
return nil
})
err = b.ExportAll(ctx, time.Time{})
events, 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++
}
}
fmt.Printf("exported %d issues with %s bridge\n", exportedIssues, b.Name)
// send done signal
close(done)
return nil