From 844616baf8dc628360942d57fd69f24e298e08da Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 19 Jan 2019 16:01:06 +0100 Subject: identity: more progress and fixes --- bridge/launchpad/import.go | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'bridge/launchpad/import.go') diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go index 10d25e6c..e65186ed 100644 --- a/bridge/launchpad/import.go +++ b/bridge/launchpad/import.go @@ -7,6 +7,7 @@ import ( "github.com/MichaelMure/git-bug/bridge/core" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/identity" "github.com/pkg/errors" ) @@ -20,14 +21,27 @@ func (li *launchpadImporter) Init(conf core.Configuration) error { } const keyLaunchpadID = "launchpad-id" +const keyLaunchpadLogin = "launchpad-login" -func (li *launchpadImporter) makePerson(owner LPPerson) bug.Person { - return bug.Person{ - Name: owner.Name, - Email: "", - Login: owner.Login, - AvatarUrl: "", +func (li *launchpadImporter) makePerson(repo *cache.RepoCache, owner LPPerson) (*identity.Identity, error) { + // Look first in the cache + i, err := repo.ResolveIdentityImmutableMetadata(keyLaunchpadLogin, owner.Login) + if err == nil { + return i, nil } + if _, ok := err.(identity.ErrMultipleMatch); ok { + return nil, err + } + + return repo.NewIdentityRaw( + owner.Name, + "", + owner.Login, + "", + map[string]string{ + keyLaunchpadLogin: owner.Login, + }, + ) } func (li *launchpadImporter) ImportAll(repo *cache.RepoCache) error { @@ -53,10 +67,15 @@ func (li *launchpadImporter) ImportAll(repo *cache.RepoCache) error { return err } + owner, err := li.makePerson(repo, lpBug.Owner) + if err != nil { + return err + } + if err == bug.ErrBugNotExist { createdAt, _ := time.Parse(time.RFC3339, lpBug.CreatedAt) b, err = repo.NewBugRaw( - li.makePerson(lpBug.Owner), + owner, createdAt.Unix(), lpBug.Title, lpBug.Description, @@ -94,10 +113,15 @@ func (li *launchpadImporter) ImportAll(repo *cache.RepoCache) error { continue } + owner, err := li.makePerson(repo, lpMessage.Owner) + if err != nil { + return err + } + // This is a new comment, we can add it. createdAt, _ := time.Parse(time.RFC3339, lpMessage.CreatedAt) err = b.AddCommentRaw( - li.makePerson(lpMessage.Owner), + owner, createdAt.Unix(), lpMessage.Content, nil, -- cgit From 864eae0d6bd0732260c0c56583bb77f9b25b60f6 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 17 Feb 2019 16:12:06 +0100 Subject: identity: work on higher level now, cache, first two identity commands --- bridge/launchpad/import.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bridge/launchpad/import.go') diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go index e65186ed..b70d34f0 100644 --- a/bridge/launchpad/import.go +++ b/bridge/launchpad/import.go @@ -23,7 +23,7 @@ func (li *launchpadImporter) Init(conf core.Configuration) error { const keyLaunchpadID = "launchpad-id" const keyLaunchpadLogin = "launchpad-login" -func (li *launchpadImporter) makePerson(repo *cache.RepoCache, owner LPPerson) (*identity.Identity, error) { +func (li *launchpadImporter) makePerson(repo *cache.RepoCache, owner LPPerson) (*cache.IdentityCache, error) { // Look first in the cache i, err := repo.ResolveIdentityImmutableMetadata(keyLaunchpadLogin, owner.Login) if err == nil { -- cgit From e100ee9f10dd7f600b58bf3d24b36f9b286210d6 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 24 Feb 2019 12:58:04 +0100 Subject: github: fix 3 edge-case failures --- bridge/launchpad/import.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bridge/launchpad/import.go') diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go index b70d34f0..30ec5c3f 100644 --- a/bridge/launchpad/import.go +++ b/bridge/launchpad/import.go @@ -23,7 +23,7 @@ func (li *launchpadImporter) Init(conf core.Configuration) error { const keyLaunchpadID = "launchpad-id" const keyLaunchpadLogin = "launchpad-login" -func (li *launchpadImporter) makePerson(repo *cache.RepoCache, owner LPPerson) (*cache.IdentityCache, error) { +func (li *launchpadImporter) ensurePerson(repo *cache.RepoCache, owner LPPerson) (*cache.IdentityCache, error) { // Look first in the cache i, err := repo.ResolveIdentityImmutableMetadata(keyLaunchpadLogin, owner.Login) if err == nil { @@ -67,7 +67,7 @@ func (li *launchpadImporter) ImportAll(repo *cache.RepoCache) error { return err } - owner, err := li.makePerson(repo, lpBug.Owner) + owner, err := li.ensurePerson(repo, lpBug.Owner) if err != nil { return err } @@ -100,7 +100,7 @@ func (li *launchpadImporter) ImportAll(repo *cache.RepoCache) error { // The Launchpad API returns the bug description as the first // comment, so skip it. for _, lpMessage := range lpBug.Messages[1:] { - _, err := b.ResolveTargetWithMetadata(keyLaunchpadID, lpMessage.ID) + _, err := b.ResolveOperationWithMetadata(keyLaunchpadID, lpMessage.ID) if err != nil && err != cache.ErrNoMatchingOp { return errors.Wrapf(err, "failed to fetch comments for bug #%s", lpBugID) } @@ -113,14 +113,14 @@ func (li *launchpadImporter) ImportAll(repo *cache.RepoCache) error { continue } - owner, err := li.makePerson(repo, lpMessage.Owner) + owner, err := li.ensurePerson(repo, lpMessage.Owner) if err != nil { return err } // This is a new comment, we can add it. createdAt, _ := time.Parse(time.RFC3339, lpMessage.CreatedAt) - err = b.AddCommentRaw( + _, err = b.AddCommentRaw( owner, createdAt.Unix(), lpMessage.Content, -- cgit