diff options
-rw-r--r-- | bug/bug.go | 1 | ||||
-rw-r--r-- | bug/person.go | 19 | ||||
-rw-r--r-- | commands/new.go | 2 | ||||
-rw-r--r-- | repository/git.go | 11 | ||||
-rw-r--r-- | repository/repo.go | 5 |
5 files changed, 36 insertions, 2 deletions
@@ -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) +} diff --git a/commands/new.go b/commands/new.go index 0156477e..43bfd212 100644 --- a/commands/new.go +++ b/commands/new.go @@ -62,6 +62,8 @@ func newBug(repo repository.Repo, args []string) error { fmt.Println(bug) + author.Store(repo) + return nil } diff --git a/repository/git.go b/repository/git.go index 309641f6..679d24fc 100644 --- a/repository/git.go +++ b/repository/git.go @@ -114,6 +114,17 @@ func (repo *GitRepo) PushRefs(remote string, refPattern string) error { return nil } +// StoreData will store arbitrary data and return the corresponding hash +func (repo *GitRepo) StoreData(data []byte) (Hash, error) { + var stdin = bytes.NewReader(data) + var stdout bytes.Buffer + var stderr bytes.Buffer + + err := repo.runGitCommandWithIO(stdin, &stdout, &stderr, "hash-object", "--stdin", "-w") + + return Hash(stdout.String()), err +} + /* // //// GetSubmitStrategy returns the way in which a review is submitted diff --git a/repository/repo.go b/repository/repo.go index 11bb132e..ef7215ee 100644 --- a/repository/repo.go +++ b/repository/repo.go @@ -1,6 +1,8 @@ // Package repository contains helper methods for working with a Git repo. package repository +type Hash string + // Repo represents a source code repository. type Repo interface { // GetPath returns the path to the repo. @@ -20,4 +22,7 @@ type Repo interface { // PushRefs push git refs to a remote PushRefs(remote string, refPattern string) error + + // StoreData will store arbitrary data and return the corresponding hash + StoreData([]byte) (Hash, error) } |