From e231b6e83956635e5e4923c064cab19e6730150a Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 15 Feb 2020 15:39:49 +0100 Subject: bridges: pass the context to Init for when a client build process needs it --- bridge/core/bridge.go | 20 ++++++-------------- bridge/core/interfaces.go | 4 ++-- bridge/github/export.go | 2 +- bridge/github/export_test.go | 7 ++++--- bridge/github/import.go | 2 +- bridge/github/import_test.go | 5 +++-- bridge/gitlab/export.go | 2 +- bridge/gitlab/export_test.go | 7 ++++--- bridge/gitlab/import.go | 2 +- bridge/gitlab/import_test.go | 5 +++-- bridge/launchpad/import.go | 2 +- 11 files changed, 27 insertions(+), 31 deletions(-) (limited to 'bridge') diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go index c72ff6b4..10f6b109 100644 --- a/bridge/core/bridge.go +++ b/bridge/core/bridge.go @@ -299,14 +299,14 @@ func (b *Bridge) getExporter() Exporter { return b.exporter } -func (b *Bridge) ensureImportInit() error { +func (b *Bridge) ensureImportInit(ctx context.Context) error { if b.initImportDone { return nil } importer := b.getImporter() if importer != nil { - err := importer.Init(b.repo, b.conf) + err := importer.Init(ctx, b.repo, b.conf) if err != nil { return err } @@ -316,22 +316,14 @@ func (b *Bridge) ensureImportInit() error { return nil } -func (b *Bridge) ensureExportInit() error { +func (b *Bridge) ensureExportInit(ctx context.Context) error { if b.initExportDone { return nil } - importer := b.getImporter() - if importer != nil { - err := importer.Init(b.repo, b.conf) - if err != nil { - return err - } - } - exporter := b.getExporter() if exporter != nil { - err := exporter.Init(b.repo, b.conf) + err := exporter.Init(ctx, b.repo, b.conf) if err != nil { return err } @@ -355,7 +347,7 @@ func (b *Bridge) ImportAllSince(ctx context.Context, since time.Time) (<-chan Im return nil, err } - err = b.ensureImportInit() + err = b.ensureImportInit(ctx) if err != nil { return nil, err } @@ -409,7 +401,7 @@ func (b *Bridge) ExportAll(ctx context.Context, since time.Time) (<-chan ExportR return nil, err } - err = b.ensureExportInit() + err = b.ensureExportInit(ctx) if err != nil { return nil, err } diff --git a/bridge/core/interfaces.go b/bridge/core/interfaces.go index 63340a95..f20f1642 100644 --- a/bridge/core/interfaces.go +++ b/bridge/core/interfaces.go @@ -36,11 +36,11 @@ type BridgeImpl interface { } type Importer interface { - Init(repo *cache.RepoCache, conf Configuration) error + Init(ctx context.Context, repo *cache.RepoCache, conf Configuration) error ImportAll(ctx context.Context, repo *cache.RepoCache, since time.Time) (<-chan ImportResult, error) } type Exporter interface { - Init(repo *cache.RepoCache, conf Configuration) error + Init(ctx context.Context, repo *cache.RepoCache, conf Configuration) error ExportAll(ctx context.Context, repo *cache.RepoCache, since time.Time) (<-chan ExportResult, error) } diff --git a/bridge/github/export.go b/bridge/github/export.go index 6cee4188..12b62fa6 100644 --- a/bridge/github/export.go +++ b/bridge/github/export.go @@ -53,7 +53,7 @@ type githubExporter struct { } // Init . -func (ge *githubExporter) Init(repo *cache.RepoCache, conf core.Configuration) error { +func (ge *githubExporter) Init(_ context.Context, repo *cache.RepoCache, conf core.Configuration) error { ge.conf = conf ge.identityClient = make(map[entity.Id]*githubv4.Client) ge.cachedOperationIDs = make(map[entity.Id]string) diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go index a25d56d7..acbd657a 100644 --- a/bridge/github/export_test.go +++ b/bridge/github/export_test.go @@ -185,15 +185,16 @@ func TestPushPull(t *testing.T) { return deleteRepository(projectName, envUser, envToken) }) + ctx := context.Background() + // initialize exporter exporter := &githubExporter{} - err = exporter.Init(backend, core.Configuration{ + err = exporter.Init(ctx, backend, core.Configuration{ confKeyOwner: envUser, confKeyProject: projectName, }) require.NoError(t, err) - ctx := context.Background() start := time.Now() // export all bugs @@ -215,7 +216,7 @@ func TestPushPull(t *testing.T) { require.NoError(t, err) importer := &githubImporter{} - err = importer.Init(backend, core.Configuration{ + err = importer.Init(ctx, backend, core.Configuration{ confKeyOwner: envUser, confKeyProject: projectName, }) diff --git a/bridge/github/import.go b/bridge/github/import.go index 3267c013..b30be73a 100644 --- a/bridge/github/import.go +++ b/bridge/github/import.go @@ -29,7 +29,7 @@ type githubImporter struct { out chan<- core.ImportResult } -func (gi *githubImporter) Init(repo *cache.RepoCache, conf core.Configuration) error { +func (gi *githubImporter) Init(_ context.Context, repo *cache.RepoCache, conf core.Configuration) error { gi.conf = conf creds, err := auth.List(repo, auth.WithTarget(target), auth.WithKind(auth.KindToken)) diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go index 4f75f368..20b1b71e 100644 --- a/bridge/github/import_test.go +++ b/bridge/github/import_test.go @@ -149,14 +149,15 @@ func Test_Importer(t *testing.T) { err = auth.Store(repo, token) require.NoError(t, err) + ctx := context.Background() + importer := &githubImporter{} - err = importer.Init(backend, core.Configuration{ + err = importer.Init(ctx, backend, core.Configuration{ confKeyOwner: "MichaelMure", confKeyProject: "git-bug-test-github-bridge", }) require.NoError(t, err) - ctx := context.Background() start := time.Now() events, err := importer.ImportAll(ctx, backend, time.Time{}) diff --git a/bridge/gitlab/export.go b/bridge/gitlab/export.go index 156aabaa..918e6b5e 100644 --- a/bridge/gitlab/export.go +++ b/bridge/gitlab/export.go @@ -38,7 +38,7 @@ type gitlabExporter struct { } // Init . -func (ge *gitlabExporter) Init(repo *cache.RepoCache, conf core.Configuration) error { +func (ge *gitlabExporter) Init(_ context.Context, repo *cache.RepoCache, conf core.Configuration) error { ge.conf = conf ge.identityClient = make(map[entity.Id]*gitlab.Client) ge.cachedOperationIDs = make(map[string]string) diff --git a/bridge/gitlab/export_test.go b/bridge/gitlab/export_test.go index 5fbb392f..d704ac3b 100644 --- a/bridge/gitlab/export_test.go +++ b/bridge/gitlab/export_test.go @@ -191,15 +191,16 @@ func TestPushPull(t *testing.T) { return deleteRepository(context.TODO(), projectID, token) }) + ctx := context.Background() + // initialize exporter exporter := &gitlabExporter{} - err = exporter.Init(backend, core.Configuration{ + err = exporter.Init(ctx, backend, core.Configuration{ confKeyProjectID: strconv.Itoa(projectID), confKeyGitlabBaseUrl: defaultBaseURL, }) require.NoError(t, err) - ctx := context.Background() start := time.Now() // export all bugs @@ -221,7 +222,7 @@ func TestPushPull(t *testing.T) { require.NoError(t, err) importer := &gitlabImporter{} - err = importer.Init(backend, core.Configuration{ + err = importer.Init(ctx, backend, core.Configuration{ confKeyProjectID: strconv.Itoa(projectID), confKeyGitlabBaseUrl: defaultBaseURL, }) diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index c8d74bef..5faf5c48 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -30,7 +30,7 @@ type gitlabImporter struct { out chan<- core.ImportResult } -func (gi *gitlabImporter) Init(repo *cache.RepoCache, conf core.Configuration) error { +func (gi *gitlabImporter) Init(_ context.Context, repo *cache.RepoCache, conf core.Configuration) error { gi.conf = conf creds, err := auth.List(repo, diff --git a/bridge/gitlab/import_test.go b/bridge/gitlab/import_test.go index b70b291e..ea7acc18 100644 --- a/bridge/gitlab/import_test.go +++ b/bridge/gitlab/import_test.go @@ -104,14 +104,15 @@ func TestImport(t *testing.T) { err = auth.Store(repo, token) require.NoError(t, err) + ctx := context.Background() + importer := &gitlabImporter{} - err = importer.Init(backend, core.Configuration{ + err = importer.Init(ctx, backend, core.Configuration{ confKeyProjectID: projectID, confKeyGitlabBaseUrl: defaultBaseURL, }) require.NoError(t, err) - ctx := context.Background() start := time.Now() events, err := importer.ImportAll(ctx, backend, time.Time{}) diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go index 5bca8e63..dfcbb95e 100644 --- a/bridge/launchpad/import.go +++ b/bridge/launchpad/import.go @@ -15,7 +15,7 @@ type launchpadImporter struct { conf core.Configuration } -func (li *launchpadImporter) Init(repo *cache.RepoCache, conf core.Configuration) error { +func (li *launchpadImporter) Init(_ context.Context, repo *cache.RepoCache, conf core.Configuration) error { li.conf = conf return nil } -- cgit