aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
Diffstat (limited to 'bug')
-rw-r--r--bug/bug.go16
-rw-r--r--bug/bug_actions.go9
-rw-r--r--bug/op_add_comment_test.go4
-rw-r--r--bug/snapshot.go4
4 files changed, 16 insertions, 17 deletions
diff --git a/bug/bug.go b/bug/bug.go
index d22a2f5e..eb0337a4 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -29,18 +29,12 @@ const editClockEntryPattern = "edit-clock-%d"
var ErrBugNotExist = errors.New("bug doesn't exist")
-type ErrMultipleMatch struct {
- Matching []entity.Id
+func NewErrMultipleMatchBug(matching []entity.Id) *entity.ErrMultipleMatch {
+ return entity.NewErrMultipleMatch("bug", matching)
}
-func (e ErrMultipleMatch) Error() string {
- matching := make([]string, len(e.Matching))
-
- for i, match := range e.Matching {
- matching[i] = match.String()
- }
-
- return fmt.Sprintf("Multiple matching bug found:\n%s", strings.Join(matching, "\n"))
+func NewErrMultipleMatchOp(matching []entity.Id) *entity.ErrMultipleMatch {
+ return entity.NewErrMultipleMatch("operation", matching)
}
var _ Interface = &Bug{}
@@ -100,7 +94,7 @@ func FindLocalBug(repo repository.ClockedRepo, prefix string) (*Bug, error) {
}
if len(matching) > 1 {
- return nil, ErrMultipleMatch{Matching: matching}
+ return nil, NewErrMultipleMatchBug(matching)
}
return ReadLocalBug(repo, matching[0])
diff --git a/bug/bug_actions.go b/bug/bug_actions.go
index e6fc12d5..cb0d0f7d 100644
--- a/bug/bug_actions.go
+++ b/bug/bug_actions.go
@@ -65,8 +65,13 @@ func MergeAll(repo repository.ClockedRepo, remote string) <-chan entity.MergeRes
}
for _, remoteRef := range remoteRefs {
- refSplitted := strings.Split(remoteRef, "/")
- id := refSplitted[len(refSplitted)-1]
+ refSplit := strings.Split(remoteRef, "/")
+ id := entity.Id(refSplit[len(refSplit)-1])
+
+ if err := id.Validate(); err != nil {
+ out <- entity.NewMergeInvalidStatus(id, errors.Wrap(err, "invalid ref").Error())
+ continue
+ }
remoteBug, err := readBug(repo, remoteRef)
diff --git a/bug/op_add_comment_test.go b/bug/op_add_comment_test.go
index 55bafe36..60364cf1 100644
--- a/bug/op_add_comment_test.go
+++ b/bug/op_add_comment_test.go
@@ -2,12 +2,12 @@ package bug
import (
"encoding/json"
- "fmt"
"testing"
"time"
- "github.com/MichaelMure/git-bug/identity"
"github.com/stretchr/testify/assert"
+
+ "github.com/MichaelMure/git-bug/identity"
)
func TestAddCommentSerialize(t *testing.T) {
diff --git a/bug/snapshot.go b/bug/snapshot.go
index a937200f..39366c6d 100644
--- a/bug/snapshot.go
+++ b/bug/snapshot.go
@@ -66,9 +66,9 @@ func (snap *Snapshot) SearchTimelineItem(id entity.Id) (TimelineItem, error) {
}
// SearchComment will search for a comment matching the given hash
-func (snap *Snapshot) SearchComment(id string) (*Comment, error) {
+func (snap *Snapshot) SearchComment(id entity.Id) (*Comment, error) {
for _, c := range snap.Comments {
- if c.id.String() == id {
+ if c.id == id {
return &c, nil
}
}