diff options
Diffstat (limited to 'cache')
-rw-r--r-- | cache/bug_excerpt.go | 15 | ||||
-rw-r--r-- | cache/filter.go | 3 | ||||
-rw-r--r-- | cache/identity_excerpt.go | 17 | ||||
-rw-r--r-- | cache/repo_cache.go | 10 |
4 files changed, 35 insertions, 10 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go index 10e522f9..d0d0aa60 100644 --- a/cache/bug_excerpt.go +++ b/cache/bug_excerpt.go @@ -2,6 +2,7 @@ package cache import ( "encoding/gob" + "fmt" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/entity" @@ -42,11 +43,21 @@ type BugExcerpt struct { // identity.Bare data are directly embedded in the bug excerpt type LegacyAuthorExcerpt struct { - Name string + Name string + Login string } func (l LegacyAuthorExcerpt) DisplayName() string { - return l.Name + switch { + case l.Name == "" && l.Login != "": + return l.Login + case l.Name != "" && l.Login == "": + return l.Name + case l.Name != "" && l.Login != "": + return fmt.Sprintf("%s (%s)", l.Name, l.Login) + } + + panic("invalid person data") } func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt { diff --git a/cache/filter.go b/cache/filter.go index f840067b..ebe774ac 100644 --- a/cache/filter.go +++ b/cache/filter.go @@ -44,7 +44,8 @@ func AuthorFilter(query string) Filter { } // Legacy identity support - return strings.Contains(strings.ToLower(excerpt.LegacyAuthor.Name), query) + return strings.Contains(strings.ToLower(excerpt.LegacyAuthor.Name), query) || + strings.Contains(strings.ToLower(excerpt.LegacyAuthor.Login), query) } } diff --git a/cache/identity_excerpt.go b/cache/identity_excerpt.go index 06788aa5..18514e9a 100644 --- a/cache/identity_excerpt.go +++ b/cache/identity_excerpt.go @@ -2,6 +2,7 @@ package cache import ( "encoding/gob" + "fmt" "strings" "github.com/MichaelMure/git-bug/entity" @@ -20,6 +21,7 @@ type IdentityExcerpt struct { Id entity.Id Name string + Login string ImmutableMetadata map[string]string } @@ -27,6 +29,7 @@ func NewIdentityExcerpt(i *identity.Identity) *IdentityExcerpt { return &IdentityExcerpt{ Id: i.Id(), Name: i.Name(), + Login: i.Login(), ImmutableMetadata: i.ImmutableMetadata(), } } @@ -34,13 +37,23 @@ func NewIdentityExcerpt(i *identity.Identity) *IdentityExcerpt { // DisplayName return a non-empty string to display, representing the // identity, based on the non-empty values. func (i *IdentityExcerpt) DisplayName() string { - return i.Name + switch { + case i.Name == "" && i.Login != "": + return i.Login + case i.Name != "" && i.Login == "": + return i.Name + case i.Name != "" && i.Login != "": + return fmt.Sprintf("%s (%s)", i.Name, i.Login) + } + + panic("invalid person data") } // Match matches a query with the identity name, login and ID prefixes func (i *IdentityExcerpt) Match(query string) bool { return i.Id.HasPrefix(query) || - strings.Contains(strings.ToLower(i.Name), query) + strings.Contains(strings.ToLower(i.Name), query) || + strings.Contains(strings.ToLower(i.Login), query) } /* diff --git a/cache/repo_cache.go b/cache/repo_cache.go index 395fb662..d859a966 100644 --- a/cache/repo_cache.go +++ b/cache/repo_cache.go @@ -1037,17 +1037,17 @@ func (c *RepoCache) NewIdentityFromGitUserRaw(metadata map[string]string) (*Iden // NewIdentity create a new identity // The new identity is written in the repository (commit) func (c *RepoCache) NewIdentity(name string, email string) (*IdentityCache, error) { - return c.NewIdentityRaw(name, email, "", nil) + return c.NewIdentityRaw(name, email, "", "", nil) } // NewIdentityFull create a new identity // The new identity is written in the repository (commit) -func (c *RepoCache) NewIdentityFull(name string, email string, avatarUrl string) (*IdentityCache, error) { - return c.NewIdentityRaw(name, email, avatarUrl, nil) +func (c *RepoCache) NewIdentityFull(name string, email string, login string, avatarUrl string) (*IdentityCache, error) { + return c.NewIdentityRaw(name, email, login, avatarUrl, nil) } -func (c *RepoCache) NewIdentityRaw(name string, email string, avatarUrl string, metadata map[string]string) (*IdentityCache, error) { - i := identity.NewIdentityFull(name, email, avatarUrl) +func (c *RepoCache) NewIdentityRaw(name string, email string, login string, avatarUrl string, metadata map[string]string) (*IdentityCache, error) { + i := identity.NewIdentityFull(name, email, login, avatarUrl) return c.finishIdentity(i, metadata) } |