person.go

 1package bug
 2
 3import (
 4	"errors"
 5	"strings"
 6
 7	"github.com/MichaelMure/git-bug/repository"
 8)
 9
10type Person struct {
11	Name  string `json:"name"`
12	Email string `json:"email"`
13}
14
15// GetUser will query the repository for user detail and build the corresponding Person
16func GetUser(repo repository.Repo) (Person, error) {
17	name, err := repo.GetUserName()
18	if err != nil {
19		return Person{}, err
20	}
21	if name == "" {
22		return Person{}, errors.New("User name is not configured in git yet. Please use `git config --global user.name \"John Doe\"`")
23	}
24
25	email, err := repo.GetUserEmail()
26	if err != nil {
27		return Person{}, err
28	}
29	if email == "" {
30		return Person{}, errors.New("User name is not configured in git yet. Please use `git config --global user.email johndoe@example.com`")
31	}
32
33	return Person{Name: name, Email: email}, nil
34}
35
36// Match tell is the Person match the given query string
37func (p Person) Match(query string) bool {
38	return strings.Contains(strings.ToLower(p.Name), strings.ToLower(query))
39}