aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
Diffstat (limited to 'bug')
-rw-r--r--bug/comment.go3
-rw-r--r--bug/op_add_comment.go3
-rw-r--r--bug/op_create.go3
-rw-r--r--bug/op_create_test.go3
-rw-r--r--bug/op_edit_comment.go3
-rw-r--r--bug/op_label_change.go5
-rw-r--r--bug/op_noop.go2
-rw-r--r--bug/op_set_metadata.go5
-rw-r--r--bug/op_set_status.go5
-rw-r--r--bug/op_set_title.go5
-rw-r--r--bug/time.go9
-rw-r--r--bug/timeline.go7
12 files changed, 29 insertions, 24 deletions
diff --git a/bug/comment.go b/bug/comment.go
index 84d34299..f7a6eada 100644
--- a/bug/comment.go
+++ b/bug/comment.go
@@ -3,6 +3,7 @@ package bug
import (
"github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
+ "github.com/MichaelMure/git-bug/util/timestamp"
"github.com/dustin/go-humanize"
)
@@ -14,7 +15,7 @@ type Comment struct {
// Creation time of the comment.
// Should be used only for human display, never for ordering as we can't rely on it in a distributed system.
- UnixTime Timestamp
+ UnixTime timestamp.Timestamp
}
// FormatTimeRel format the UnixTime of the comment for human consumption
diff --git a/bug/op_add_comment.go b/bug/op_add_comment.go
index ba5d611e..9ecef941 100644
--- a/bug/op_add_comment.go
+++ b/bug/op_add_comment.go
@@ -7,6 +7,7 @@ import (
"github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/text"
+ "github.com/MichaelMure/git-bug/util/timestamp"
)
var _ Operation = &AddCommentOperation{}
@@ -32,7 +33,7 @@ func (op *AddCommentOperation) Apply(snapshot *Snapshot) {
Message: op.Message,
Author: op.Author,
Files: op.Files,
- UnixTime: Timestamp(op.UnixTime),
+ UnixTime: timestamp.Timestamp(op.UnixTime),
}
snapshot.Comments = append(snapshot.Comments, comment)
diff --git a/bug/op_create.go b/bug/op_create.go
index 1d157e67..42d40f71 100644
--- a/bug/op_create.go
+++ b/bug/op_create.go
@@ -8,6 +8,7 @@ import (
"github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/text"
+ "github.com/MichaelMure/git-bug/util/timestamp"
)
var _ Operation = &CreateOperation{}
@@ -34,7 +35,7 @@ func (op *CreateOperation) Apply(snapshot *Snapshot) {
comment := Comment{
Message: op.Message,
Author: op.Author,
- UnixTime: Timestamp(op.UnixTime),
+ UnixTime: timestamp.Timestamp(op.UnixTime),
}
snapshot.Comments = []Comment{comment}
diff --git a/bug/op_create_test.go b/bug/op_create_test.go
index c41c5687..92ac191d 100644
--- a/bug/op_create_test.go
+++ b/bug/op_create_test.go
@@ -6,6 +6,7 @@ import (
"time"
"github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/util/timestamp"
"github.com/stretchr/testify/assert"
)
@@ -22,7 +23,7 @@ func TestCreate(t *testing.T) {
hash, err := create.Hash()
assert.NoError(t, err)
- comment := Comment{Author: rene, Message: "message", UnixTime: Timestamp(create.UnixTime)}
+ comment := Comment{Author: rene, Message: "message", UnixTime: timestamp.Timestamp(create.UnixTime)}
expected := Snapshot{
Title: "title",
diff --git a/bug/op_edit_comment.go b/bug/op_edit_comment.go
index 3ff16653..527b7440 100644
--- a/bug/op_edit_comment.go
+++ b/bug/op_edit_comment.go
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/util/timestamp"
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/text"
@@ -58,7 +59,7 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
comment := Comment{
Message: op.Message,
Files: op.Files,
- UnixTime: Timestamp(op.UnixTime),
+ UnixTime: timestamp.Timestamp(op.UnixTime),
}
switch target.(type) {
diff --git a/bug/op_label_change.go b/bug/op_label_change.go
index b0dd2c33..84542b6e 100644
--- a/bug/op_label_change.go
+++ b/bug/op_label_change.go
@@ -6,6 +6,7 @@ import (
"sort"
"github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/util/timestamp"
"github.com/MichaelMure/git-bug/util/git"
"github.com/pkg/errors"
@@ -68,7 +69,7 @@ AddLoop:
item := &LabelChangeTimelineItem{
hash: hash,
Author: op.Author,
- UnixTime: Timestamp(op.UnixTime),
+ UnixTime: timestamp.Timestamp(op.UnixTime),
Added: op.Added,
Removed: op.Removed,
}
@@ -162,7 +163,7 @@ func NewLabelChangeOperation(author identity.Interface, unixTime int64, added, r
type LabelChangeTimelineItem struct {
hash git.Hash
Author identity.Interface
- UnixTime Timestamp
+ UnixTime timestamp.Timestamp
Added []Label
Removed []Label
}
diff --git a/bug/op_noop.go b/bug/op_noop.go
index fbc112a8..3cd9f39a 100644
--- a/bug/op_noop.go
+++ b/bug/op_noop.go
@@ -11,7 +11,7 @@ var _ Operation = &NoOpOperation{}
// NoOpOperation is an operation that does not change the bug state. It can
// however be used to store arbitrary metadata in the bug history, for example
-// to support a bridge feature
+// to support a bridge feature.
type NoOpOperation struct {
OpBase
}
diff --git a/bug/op_set_metadata.go b/bug/op_set_metadata.go
index 57b78667..7616a591 100644
--- a/bug/op_set_metadata.go
+++ b/bug/op_set_metadata.go
@@ -2,6 +2,7 @@ package bug
import (
"encoding/json"
+ "fmt"
"github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
@@ -55,6 +56,10 @@ func (op *SetMetadataOperation) Validate() error {
return err
}
+ if !op.Target.IsValid() {
+ return fmt.Errorf("target hash is invalid")
+ }
+
return nil
}
diff --git a/bug/op_set_status.go b/bug/op_set_status.go
index 6deb1675..0105d78d 100644
--- a/bug/op_set_status.go
+++ b/bug/op_set_status.go
@@ -5,6 +5,7 @@ import (
"github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
+ "github.com/MichaelMure/git-bug/util/timestamp"
"github.com/pkg/errors"
)
@@ -37,7 +38,7 @@ func (op *SetStatusOperation) Apply(snapshot *Snapshot) {
item := &SetStatusTimelineItem{
hash: hash,
Author: op.Author,
- UnixTime: Timestamp(op.UnixTime),
+ UnixTime: timestamp.Timestamp(op.UnixTime),
Status: op.Status,
}
@@ -114,7 +115,7 @@ func NewSetStatusOp(author identity.Interface, unixTime int64, status Status) *S
type SetStatusTimelineItem struct {
hash git.Hash
Author identity.Interface
- UnixTime Timestamp
+ UnixTime timestamp.Timestamp
Status Status
}
diff --git a/bug/op_set_title.go b/bug/op_set_title.go
index ae6484c6..084838cb 100644
--- a/bug/op_set_title.go
+++ b/bug/op_set_title.go
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/util/timestamp"
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/text"
@@ -41,7 +42,7 @@ func (op *SetTitleOperation) Apply(snapshot *Snapshot) {
item := &SetTitleTimelineItem{
hash: hash,
Author: op.Author,
- UnixTime: Timestamp(op.UnixTime),
+ UnixTime: timestamp.Timestamp(op.UnixTime),
Title: op.Title,
Was: op.Was,
}
@@ -139,7 +140,7 @@ func NewSetTitleOp(author identity.Interface, unixTime int64, title string, was
type SetTitleTimelineItem struct {
hash git.Hash
Author identity.Interface
- UnixTime Timestamp
+ UnixTime timestamp.Timestamp
Title string
Was string
}
diff --git a/bug/time.go b/bug/time.go
deleted file mode 100644
index a085e8e9..00000000
--- a/bug/time.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package bug
-
-import "time"
-
-type Timestamp int64
-
-func (t Timestamp) Time() time.Time {
- return time.Unix(int64(t), 0)
-}
diff --git a/bug/timeline.go b/bug/timeline.go
index 306ffa9e..d8ee2c6b 100644
--- a/bug/timeline.go
+++ b/bug/timeline.go
@@ -5,6 +5,7 @@ import (
"github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
+ "github.com/MichaelMure/git-bug/util/timestamp"
)
type TimelineItem interface {
@@ -19,7 +20,7 @@ type CommentHistoryStep struct {
Author identity.Interface
// The new message
Message string
- UnixTime Timestamp
+ UnixTime timestamp.Timestamp
}
// CommentTimelineItem is a TimelineItem that holds a Comment and its edition history
@@ -28,8 +29,8 @@ type CommentTimelineItem struct {
Author identity.Interface
Message string
Files []git.Hash
- CreatedAt Timestamp
- LastEdit Timestamp
+ CreatedAt timestamp.Timestamp
+ LastEdit timestamp.Timestamp
History []CommentHistoryStep
}