aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-10-07 18:27:23 +0200
committerMichael Muré <batolettre@gmail.com>2018-10-07 18:27:23 +0200
commit7cb7994cdae848053487d00c1730d1e865fb8623 (patch)
treebc9be185e81479d8d3e5b0fc636daea011a64e4c /bug
parent03202fed493539c8d1fdcad7254687f951d0ca4a (diff)
downloadgit-bug-7cb7994cdae848053487d00c1730d1e865fb8623.tar.gz
github: also pull users email
Diffstat (limited to 'bug')
-rw-r--r--bug/person.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/bug/person.go b/bug/person.go
index c79e9935..449e2262 100644
--- a/bug/person.go
+++ b/bug/person.go
@@ -12,6 +12,7 @@ import (
type Person struct {
Name string `json:"name"`
Email string `json:"email"`
+ Login string `json:"login"`
AvatarUrl string `json:"avatar_url"`
}
@@ -38,12 +39,15 @@ func GetUser(repo repository.Repo) (Person, error) {
// Match tell is the Person match the given query string
func (p Person) Match(query string) bool {
- return strings.Contains(strings.ToLower(p.Name), strings.ToLower(query))
+ query = strings.ToLower(query)
+
+ return strings.Contains(strings.ToLower(p.Name), query) ||
+ strings.Contains(strings.ToLower(p.Login), query)
}
func (p Person) Validate() error {
- if text.Empty(p.Name) {
- return fmt.Errorf("name is not set")
+ if text.Empty(p.Name) && text.Empty(p.Login) {
+ return fmt.Errorf("either name or login should be set")
}
if strings.Contains(p.Name, "\n") {
@@ -54,6 +58,14 @@ func (p Person) Validate() error {
return fmt.Errorf("name is not fully printable")
}
+ if strings.Contains(p.Login, "\n") {
+ return fmt.Errorf("login should be a single line")
+ }
+
+ if !text.Safe(p.Login) {
+ return fmt.Errorf("login is not fully printable")
+ }
+
if strings.Contains(p.Email, "\n") {
return fmt.Errorf("email should be a single line")
}
@@ -69,6 +81,15 @@ func (p Person) Validate() error {
return nil
}
-func (p Person) String() string {
- return fmt.Sprintf("%s <%s>", p.Name, p.Email)
+func (p Person) DisplayName() string {
+ switch {
+ case p.Name == "" && p.Login != "":
+ return p.Login
+ case p.Name != "" && p.Login == "":
+ return p.Name
+ case p.Name != "" && p.Login != "":
+ return fmt.Sprintf("%s (%s)", p.Name, p.Login)
+ }
+
+ panic("invalid person data")
}