aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/launchpad/import.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-01-19 16:01:06 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:40:21 +0100
commit844616baf8dc628360942d57fd69f24e298e08da (patch)
tree3fd635e08a06de60618d47ab022554a1f78364de /bridge/launchpad/import.go
parentbdbe9e7e8256fff820efe1ce707e7154d517ecb3 (diff)
downloadgit-bug-844616baf8dc628360942d57fd69f24e298e08da.tar.gz
identity: more progress and fixes
Diffstat (limited to 'bridge/launchpad/import.go')
-rw-r--r--bridge/launchpad/import.go40
1 files changed, 32 insertions, 8 deletions
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,