From cda8114fda8d349bbaeefb42cc33ba715d41cf08 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Thu, 12 Jul 2018 15:14:37 +0200 Subject: store user info in the datastore --- bug/bug.go | 1 + bug/person.go | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'bug') diff --git a/bug/bug.go b/bug/bug.go index 08743e85..33da1326 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -4,3 +4,4 @@ type Bug struct { Title string Comments []Comment } + diff --git a/bug/person.go b/bug/person.go index 41f37ef4..05cc43fa 100644 --- a/bug/person.go +++ b/bug/person.go @@ -1,15 +1,17 @@ package bug import ( + "encoding/json" "github.com/MichaelMure/git-bug/repository" "github.com/pkg/errors" ) type Person struct { - Name string - Email string + Name string `json:"name"` + Email string `json:"email"` } +// GetUser will query the repository for user detail and build the corresponding Person func GetUser(repo repository.Repo) (Person, error) { name, err := repo.GetUserName() if err != nil { @@ -29,3 +31,16 @@ func GetUser(repo repository.Repo) (Person, error) { return Person{Name: name, Email: email}, nil } + +// Store will convert the Person to JSON and store it in the internal git datastore +// Return the git hash handle of the data +func (person *Person) Store(repo repository.Repo) (repository.Hash, error) { + + data, err := json.Marshal(person) + + if err != nil { + return "", err + } + + return repo.StoreData(data) +} -- cgit