2018-07-12 13:44:46 +03:00
|
|
|
package bug
|
|
|
|
|
|
|
|
import (
|
2018-07-13 17:13:40 +03:00
|
|
|
"errors"
|
2018-09-09 21:14:52 +03:00
|
|
|
"strings"
|
2018-08-13 19:32:11 +03:00
|
|
|
|
2018-07-12 13:44:46 +03:00
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Person struct {
|
2018-09-12 17:57:04 +03:00
|
|
|
Name string `json:"name"`
|
|
|
|
Email string `json:"email"`
|
2018-07-12 13:44:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:14:37 +03:00
|
|
|
// GetUser will query the repository for user detail and build the corresponding Person
|
2018-07-12 13:44:46 +03:00
|
|
|
func GetUser(repo repository.Repo) (Person, error) {
|
|
|
|
name, err := repo.GetUserName()
|
|
|
|
if err != nil {
|
|
|
|
return Person{}, err
|
|
|
|
}
|
|
|
|
if name == "" {
|
|
|
|
return Person{}, errors.New("User name is not configured in git yet. Please use `git config --global user.name \"John Doe\"`")
|
|
|
|
}
|
|
|
|
|
|
|
|
email, err := repo.GetUserEmail()
|
|
|
|
if err != nil {
|
|
|
|
return Person{}, err
|
|
|
|
}
|
|
|
|
if email == "" {
|
|
|
|
return Person{}, errors.New("User name is not configured in git yet. Please use `git config --global user.email johndoe@example.com`")
|
|
|
|
}
|
|
|
|
|
|
|
|
return Person{Name: name, Email: email}, nil
|
|
|
|
}
|
2018-09-09 21:14:52 +03:00
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|