bridges: pass the context to Init for when a client build process needs it

Michael Muré created

Change summary

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 +-
identity/bare.go             |  2 ++
12 files changed, 29 insertions(+), 31 deletions(-)

Detailed changes

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
 	}

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)
 }

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)

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,
 	})

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))

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{})

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)

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,
 	})

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,

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{})

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
 }

identity/bare.go 🔗

@@ -21,6 +21,8 @@ var _ entity.Interface = &Bare{}
 //
 // in particular, this identity is designed to be compatible with the handling of
 // identities in the early version of git-bug.
+// Deprecated: legacy identity for compat, might make sense to ditch entirely for
+// simplicity but that would be a breaking change.
 type Bare struct {
 	id        entity.Id
 	name      string