diff options
author | Amine Hilaly <hilalyamine@gmail.com> | 2019-07-17 00:09:02 +0200 |
---|---|---|
committer | Amine Hilaly <hilalyamine@gmail.com> | 2019-07-23 17:18:04 +0200 |
commit | ffb8d34e4f04b678b3f4785a8247762ca7c06c4a (patch) | |
tree | 868053906bb2f09611b6059cc725a0b1eb245f34 /bridge | |
parent | 8b6c896369bc48599bc97181a3f3a85a9425af87 (diff) | |
download | git-bug-ffb8d34e4f04b678b3f4785a8247762ca7c06c4a.tar.gz |
bridge/gitlab: check identity cache in ensurePerson
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/gitlab/import.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index 1ac8eaf3..4eeb3813 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -2,6 +2,7 @@ package gitlab import ( "fmt" + "strconv" "time" "github.com/xanzy/go-gitlab" @@ -9,6 +10,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/MichaelMure/git-bug/util/text" ) @@ -314,6 +316,18 @@ func (gi *gitlabImporter) ensureLabelEvent(repo *cache.RepoCache, b *cache.BugCa } func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.IdentityCache, error) { + // Look first in the cache + i, err := repo.ResolveIdentityImmutableMetadata(keyGitlabId, strconv.Itoa(id)) + if err == nil { + return i, nil + } + if _, ok := err.(identity.ErrMultipleMatch); ok { + return nil, err + } + + // importing a new identity + gi.importedIdentities++ + client := buildClient(gi.conf["token"]) user, _, err := client.Users.GetUser(id) @@ -327,6 +341,7 @@ func (gi *gitlabImporter) ensurePerson(repo *cache.RepoCache, id int) (*cache.Id user.Username, user.AvatarURL, map[string]string{ + keyGitlabId: strconv.Itoa(id), keyGitlabLogin: user.Username, }, ) |