diff options
author | Michael Muré <batolettre@gmail.com> | 2018-07-30 01:08:45 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-07-30 01:08:45 +0200 |
commit | 3cb0469a2200dea24aff1f414aa971d5e6fe9815 (patch) | |
tree | ce74b9f91707ae90f0dc8977af0df59eb6dc2590 /cache/cache.go | |
parent | 79b3d189186783c01acb194de825976a007dbd5f (diff) | |
download | git-bug-3cb0469a2200dea24aff1f414aa971d5e6fe9815.tar.gz |
graphql: implement a first mutation
Diffstat (limited to 'cache/cache.go')
-rw-r--r-- | cache/cache.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/cache/cache.go b/cache/cache.go index 07c5be52..2813b150 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/bug/operations" "github.com/MichaelMure/git-bug/repository" ) @@ -25,6 +26,10 @@ type RepoCacher interface { ResolveBugPrefix(prefix string) (BugCacher, error) AllBugIds() ([]string, error) ClearAllBugs() + + // Mutations + + NewBug(title string, message string) (BugCacher, error) } type BugCacher interface { @@ -164,6 +169,28 @@ func (c RepoCache) ClearAllBugs() { c.bugs = make(map[string]BugCacher) } +func (c RepoCache) NewBug(title string, message string) (BugCacher, error) { + author, err := bug.GetUser(c.repo) + if err != nil { + return nil, err + } + + b, err := operations.Create(author, title, message) + if err != nil { + return nil, err + } + + err = b.Commit(c.repo) + if err != nil { + return nil, err + } + + cached := NewBugCache(b) + c.bugs[b.Id()] = cached + + return cached, nil +} + // Bug ------------------------ type BugCache struct { |