aboutsummaryrefslogtreecommitdiffstats
path: root/cache/bug_cache.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-23 21:24:57 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-23 21:24:57 +0200
commit0514edad1a6ee06902841e0c903fc2a2119b7e95 (patch)
tree104279a8939034ab163cac9bfc124166d001dda7 /cache/bug_cache.go
parente7648996c8f278d061fe03a5c4d255049da765e5 (diff)
downloadgit-bug-0514edad1a6ee06902841e0c903fc2a2119b7e95.tar.gz
cache: maintain, write and load from disk bug excerpts
Diffstat (limited to 'cache/bug_cache.go')
-rw-r--r--cache/bug_cache.go60
1 files changed, 26 insertions, 34 deletions
diff --git a/cache/bug_cache.go b/cache/bug_cache.go
index f0fc7ff6..7df76efe 100644
--- a/cache/bug_cache.go
+++ b/cache/bug_cache.go
@@ -3,34 +3,18 @@ package cache
import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/bug/operations"
- "github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util"
)
-type BugCacher interface {
- Snapshot() *bug.Snapshot
-
- // Mutations
- AddComment(message string) error
- AddCommentWithFiles(message string, files []util.Hash) error
- ChangeLabels(added []string, removed []string) error
- Open() error
- Close() error
- SetTitle(title string) error
-
- Commit() error
- CommitAsNeeded() error
-}
-
type BugCache struct {
- repo repository.Repo
- bug *bug.WithSnapshot
+ repoCache *RepoCache
+ bug *bug.WithSnapshot
}
-func NewBugCache(repo repository.Repo, b *bug.Bug) BugCacher {
+func NewBugCache(repoCache *RepoCache, b *bug.Bug) *BugCache {
return &BugCache{
- repo: repo,
- bug: &bug.WithSnapshot{Bug: b},
+ repoCache: repoCache,
+ bug: &bug.WithSnapshot{Bug: b},
}
}
@@ -38,23 +22,31 @@ func (c *BugCache) Snapshot() *bug.Snapshot {
return c.bug.Snapshot()
}
+func (c *BugCache) notifyUpdated() error {
+ return c.repoCache.bugUpdated(c.bug.Id())
+}
+
func (c *BugCache) AddComment(message string) error {
- return c.AddCommentWithFiles(message, nil)
+ if err := c.AddCommentWithFiles(message, nil); err != nil {
+ return err
+ }
+
+ return c.notifyUpdated()
}
func (c *BugCache) AddCommentWithFiles(message string, files []util.Hash) error {
- author, err := bug.GetUser(c.repo)
+ author, err := bug.GetUser(c.repoCache.repo)
if err != nil {
return err
}
operations.CommentWithFiles(c.bug, author, message, files)
- return nil
+ return c.notifyUpdated()
}
func (c *BugCache) ChangeLabels(added []string, removed []string) error {
- author, err := bug.GetUser(c.repo)
+ author, err := bug.GetUser(c.repoCache.repo)
if err != nil {
return err
}
@@ -64,49 +56,49 @@ func (c *BugCache) ChangeLabels(added []string, removed []string) error {
return err
}
- return nil
+ return c.notifyUpdated()
}
func (c *BugCache) Open() error {
- author, err := bug.GetUser(c.repo)
+ author, err := bug.GetUser(c.repoCache.repo)
if err != nil {
return err
}
operations.Open(c.bug, author)
- return nil
+ return c.notifyUpdated()
}
func (c *BugCache) Close() error {
- author, err := bug.GetUser(c.repo)
+ author, err := bug.GetUser(c.repoCache.repo)
if err != nil {
return err
}
operations.Close(c.bug, author)
- return nil
+ return c.notifyUpdated()
}
func (c *BugCache) SetTitle(title string) error {
- author, err := bug.GetUser(c.repo)
+ author, err := bug.GetUser(c.repoCache.repo)
if err != nil {
return err
}
operations.SetTitle(c.bug, author, title)
- return nil
+ return c.notifyUpdated()
}
func (c *BugCache) Commit() error {
- return c.bug.Commit(c.repo)
+ return c.bug.Commit(c.repoCache.repo)
}
func (c *BugCache) CommitAsNeeded() error {
if c.bug.HasPendingOp() {
- return c.bug.Commit(c.repo)
+ return c.bug.Commit(c.repoCache.repo)
}
return nil
}