diff --git a/bug/comment.go b/bug/comment.go index f7727709f49a5f2b46a154fd8552b8b126772c4c..2261f6de530cf33589a103e72d1e876db86d5367 100644 --- a/bug/comment.go +++ b/bug/comment.go @@ -1,6 +1,12 @@ package bug +import "time" + type Comment struct { Author Person Message string + + // 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. + Time time.Time } diff --git a/bug/operations/add_comment.go b/bug/operations/add_comment.go index 2b83de83eac6f57e8b18f81cb3e41ecd62871fd9..1f9e341016387ab07d6f0d2615db4ad36c042c84 100644 --- a/bug/operations/add_comment.go +++ b/bug/operations/add_comment.go @@ -1,13 +1,17 @@ package operations -import "github.com/MichaelMure/git-bug/bug" +import ( + "github.com/MichaelMure/git-bug/bug" + "time" +) var _ bug.Operation = AddCommentOperation{} type AddCommentOperation struct { bug.OpBase - Message string `json:"m"` - Author bug.Person `json:"a"` + Message string + Author bug.Person + Time time.Time } func NewAddCommentOp(author bug.Person, message string) AddCommentOperation { @@ -15,6 +19,7 @@ func NewAddCommentOp(author bug.Person, message string) AddCommentOperation { OpBase: bug.OpBase{OperationType: bug.ADD_COMMENT}, Message: message, Author: author, + Time: time.Now(), } } @@ -22,6 +27,7 @@ func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { comment := bug.Comment{ Message: op.Message, Author: op.Author, + Time: op.Time, } snapshot.Comments = append(snapshot.Comments, comment) diff --git a/bug/operations/create.go b/bug/operations/create.go index 49b648a27fbb741bc9b848c945b315b9a6cc86b5..81fc58f1accaffaf79d23a56c6be4ff91a1371d0 100644 --- a/bug/operations/create.go +++ b/bug/operations/create.go @@ -3,6 +3,7 @@ package operations import ( "github.com/MichaelMure/git-bug/bug" "reflect" + "time" ) // CreateOperation define the initial creation of a bug @@ -14,6 +15,7 @@ type CreateOperation struct { Title string Message string Author bug.Person + Time time.Time } func NewCreateOp(author bug.Person, title, message string) CreateOperation { @@ -22,6 +24,7 @@ func NewCreateOp(author bug.Person, title, message string) CreateOperation { Title: title, Message: message, Author: author, + Time: time.Now(), } } @@ -37,6 +40,7 @@ func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { { Message: op.Message, Author: op.Author, + Time: op.Time, }, } return snapshot diff --git a/bug/operations/create_test.go b/bug/operations/create_test.go index 35e515ac63aee1ae73921da94e8da45d6b4d3288..bd73fc1a64b2a0919760f7ce479700022c4ebbc4 100644 --- a/bug/operations/create_test.go +++ b/bug/operations/create_test.go @@ -21,11 +21,11 @@ func TestCreate(t *testing.T) { expected := bug.Snapshot{ Title: "title", Comments: []bug.Comment{ - {Author: rene, Message: "message"}, + {Author: rene, Message: "message", Time: create.Time}, }, } if !reflect.DeepEqual(snapshot, expected) { - t.Fail() + t.Fatalf("%s different than %s", snapshot, expected) } }