From 1d42814166f783766a1b81e926c93c21244289dc Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Fri, 21 Jun 2019 01:09:05 +0200 Subject: [bridge/github] cache user token fix import typo init tests verify issue --- bridge/github/export.go | 17 +++++++---- bridge/github/export_test.go | 67 +++++++++++++++++++++++++++++++++++++++++++- bridge/github/import_test.go | 2 +- 3 files changed, 78 insertions(+), 8 deletions(-) diff --git a/bridge/github/export.go b/bridge/github/export.go index 32df8240..e7611360 100644 --- a/bridge/github/export.go +++ b/bridge/github/export.go @@ -21,7 +21,6 @@ import ( // githubImporter implement the Importer interface type githubExporter struct { - gc *githubv4.Client conf core.Configuration // a map containing @@ -45,7 +44,6 @@ type githubExporter struct { func (ge *githubExporter) Init(conf core.Configuration) error { //TODO: initialize with multiple tokens ge.conf = conf - ge.gc = buildClient(conf["token"]) ge.tokens = make(map[string]string) ge.clients = make(map[string]*githubv4.Client) ge.cachedIDs = make(map[string]string) @@ -74,6 +72,8 @@ func (ge *githubExporter) ExportAll(repo *cache.RepoCache, since time.Time) erro return err } + ge.tokens[user.Id()] = ge.conf[keyToken] + // get repository node id ge.repositoryID, err = getRepositoryNodeID( ge.conf[keyOwner], @@ -86,6 +86,7 @@ func (ge *githubExporter) ExportAll(repo *cache.RepoCache, since time.Time) erro } allBugsIds := repo.AllBugsIds() +bugLoop: for _, id := range allBugsIds { b, err := repo.ResolveBug(id) if err != nil { @@ -101,10 +102,14 @@ func (ge *githubExporter) ExportAll(repo *cache.RepoCache, since time.Time) erro // if identity participated in a bug for _, p := range snapshot.Participants { - if p.Id() == user.Id() { - // try to export the bug and it associated events - if err := ge.exportBug(b, user.Identity, since); err != nil { - return err + for userId := range ge.tokens { + if p.Id() == userId { + // try to export the bug and it associated events + if err := ge.exportBug(b, user.Identity, since); err != nil { + return err + } + + continue bugLoop } } } diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go index 710b798c..c3a835b2 100644 --- a/bridge/github/export_test.go +++ b/bridge/github/export_test.go @@ -1,7 +1,72 @@ package github -import "testing" +import ( + "fmt" + "os" + "testing" + "time" + + "github.com/MichaelMure/git-bug/bridge/core" + "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/repository" + "github.com/MichaelMure/git-bug/util/interrupt" + "github.com/stretchr/testify/require" +) func TestExporter(t *testing.T) { //TODO test strategy + tests := []struct { + name string + }{ + { + name: "bug creation", + }, + } + + repo := repository.CreateTestRepo(false) + defer repository.CleanupTestRepos(t, repo) + + backend, err := cache.NewRepoCache(repo) + require.NoError(t, err) + + defer backend.Close() + interrupt.RegisterCleaner(backend.Close) + + token := os.Getenv("GITHUB_TOKEN_PRIVATE") + if token == "" { + t.Skip("Env var GITHUB_TOKEN_PRIVATE missing") + } + + exporter := &githubExporter{} + err = exporter.Init(core.Configuration{ + keyOwner: "MichaelMure", + keyProject: "git-bug-exporter-tests", + keyToken: token, + }) + require.NoError(t, err) + + start := time.Now() + + err = exporter.ExportAll(backend, time.Time{}) + require.NoError(t, err) + + fmt.Printf("test repository exported in %f seconds\n", time.Since(start).Seconds()) + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + + }) + } +} + +func genRepoName() {} + +func createRepository() {} + +func deleteRepository() {} + +// verifyIssue is full +// comments +func verifyIssue() { + } diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go index 24356f34..5ba87993 100644 --- a/bridge/github/import_test.go +++ b/bridge/github/import_test.go @@ -190,7 +190,7 @@ func Test_Importer(t *testing.T) { assert.Equal(t, op.(*bug.EditCommentOperation).Author.Name(), ops[i].(*bug.EditCommentOperation).Author.Name()) default: - panic("Unknown operation type") + panic("unknown operation type") } } }) -- cgit