aboutsummaryrefslogtreecommitdiffstats
path: root/cache/bug_cache.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-10-01 23:34:45 +0200
committerMichael Muré <batolettre@gmail.com>2018-10-01 23:34:45 +0200
commit8ec1dd092656aed5dae22a0301bd3f85b5dabb88 (patch)
tree26ee832a2d629d48e9ac9f43fc808f17a4a77154 /cache/bug_cache.go
parentf18c2d278352f556b90ad9a52c33499665e16fa2 (diff)
downloadgit-bug-8ec1dd092656aed5dae22a0301bd3f85b5dabb88.tar.gz
github: working incremental + comment history for the first comment
Diffstat (limited to 'cache/bug_cache.go')
-rw-r--r--cache/bug_cache.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/cache/bug_cache.go b/cache/bug_cache.go
index b7c80a0c..52e9eafb 100644
--- a/cache/bug_cache.go
+++ b/cache/bug_cache.go
@@ -1,6 +1,8 @@
package cache
import (
+ "fmt"
+ "strings"
"time"
"github.com/MichaelMure/git-bug/bug"
@@ -35,6 +37,51 @@ func (c *BugCache) notifyUpdated() error {
return c.repoCache.bugUpdated(c.bug.Id())
}
+var ErrNoMatchingOp = fmt.Errorf("no matching operation found")
+
+type ErrMultipleMatchOp struct {
+ Matching []git.Hash
+}
+
+func (e ErrMultipleMatchOp) Error() string {
+ casted := make([]string, len(e.Matching))
+
+ for i := range e.Matching {
+ casted[i] = string(e.Matching[i])
+ }
+
+ return fmt.Sprintf("Multiple matching operation found:\n%s", strings.Join(casted, "\n"))
+}
+
+// ResolveTargetWithMetadata will find an operation that has the matching metadata
+func (c *BugCache) ResolveTargetWithMetadata(key string, value string) (git.Hash, error) {
+ // preallocate but empty
+ matching := make([]git.Hash, 0, 5)
+
+ it := bug.NewOperationIterator(c.bug)
+ for it.Next() {
+ op := it.Value()
+ opValue, ok := op.GetMetadata(key)
+ if ok && value == opValue {
+ h, err := op.Hash()
+ if err != nil {
+ return "", err
+ }
+ matching = append(matching, h)
+ }
+ }
+
+ if len(matching) == 0 {
+ return "", ErrNoMatchingOp
+ }
+
+ if len(matching) > 1 {
+ return "", ErrMultipleMatchOp{Matching: matching}
+ }
+
+ return matching[0], nil
+}
+
func (c *BugCache) AddComment(message string) error {
return c.AddCommentWithFiles(message, nil)
}