diff options
Diffstat (limited to 'operations')
-rw-r--r-- | operations/add_comment.go | 12 | ||||
-rw-r--r-- | operations/create.go | 12 | ||||
-rw-r--r-- | operations/create_test.go | 5 | ||||
-rw-r--r-- | operations/label_change.go | 8 | ||||
-rw-r--r-- | operations/operations_test.go | 53 | ||||
-rw-r--r-- | operations/set_status.go | 12 | ||||
-rw-r--r-- | operations/set_title.go | 8 |
7 files changed, 58 insertions, 52 deletions
diff --git a/operations/add_comment.go b/operations/add_comment.go index 65606d77..56a2c606 100644 --- a/operations/add_comment.go +++ b/operations/add_comment.go @@ -52,21 +52,21 @@ func (op AddCommentOperation) Validate() error { return nil } -func NewAddCommentOp(author bug.Person, message string, files []git.Hash) AddCommentOperation { +func NewAddCommentOp(author bug.Person, unixTime int64, message string, files []git.Hash) AddCommentOperation { return AddCommentOperation{ - OpBase: bug.NewOpBase(bug.AddCommentOp, author), + OpBase: bug.NewOpBase(bug.AddCommentOp, author, unixTime), Message: message, Files: files, } } // Convenience function to apply the operation -func Comment(b bug.Interface, author bug.Person, message string) error { - return CommentWithFiles(b, author, message, nil) +func Comment(b bug.Interface, author bug.Person, unixTime int64, message string) error { + return CommentWithFiles(b, author, unixTime, message, nil) } -func CommentWithFiles(b bug.Interface, author bug.Person, message string, files []git.Hash) error { - addCommentOp := NewAddCommentOp(author, message, files) +func CommentWithFiles(b bug.Interface, author bug.Person, unixTime int64, message string, files []git.Hash) error { + addCommentOp := NewAddCommentOp(author, unixTime, message, files) if err := addCommentOp.Validate(); err != nil { return err } diff --git a/operations/create.go b/operations/create.go index 49c69482..fd66e732 100644 --- a/operations/create.go +++ b/operations/create.go @@ -62,9 +62,9 @@ func (op CreateOperation) Validate() error { return nil } -func NewCreateOp(author bug.Person, title, message string, files []git.Hash) CreateOperation { +func NewCreateOp(author bug.Person, unixTime int64, title, message string, files []git.Hash) CreateOperation { return CreateOperation{ - OpBase: bug.NewOpBase(bug.CreateOp, author), + OpBase: bug.NewOpBase(bug.CreateOp, author, unixTime), Title: title, Message: message, Files: files, @@ -72,13 +72,13 @@ func NewCreateOp(author bug.Person, title, message string, files []git.Hash) Cre } // Convenience function to apply the operation -func Create(author bug.Person, title, message string) (*bug.Bug, error) { - return CreateWithFiles(author, title, message, nil) +func Create(author bug.Person, unixTime int64, title, message string) (*bug.Bug, error) { + return CreateWithFiles(author, unixTime, title, message, nil) } -func CreateWithFiles(author bug.Person, title, message string, files []git.Hash) (*bug.Bug, error) { +func CreateWithFiles(author bug.Person, unixTime int64, title, message string, files []git.Hash) (*bug.Bug, error) { newBug := bug.NewBug() - createOp := NewCreateOp(author, title, message, files) + createOp := NewCreateOp(author, unixTime, title, message, files) if err := createOp.Validate(); err != nil { return nil, err diff --git a/operations/create_test.go b/operations/create_test.go index a20472d3..c32b2868 100644 --- a/operations/create_test.go +++ b/operations/create_test.go @@ -4,6 +4,7 @@ import ( "github.com/MichaelMure/git-bug/bug" "reflect" "testing" + "time" ) func TestCreate(t *testing.T) { @@ -14,7 +15,9 @@ func TestCreate(t *testing.T) { Email: "rene@descartes.fr", } - create := NewCreateOp(rene, "title", "message", nil) + unix := time.Now().Unix() + + create := NewCreateOp(rene, unix, "title", "message", nil) snapshot = create.Apply(snapshot) diff --git a/operations/label_change.go b/operations/label_change.go index 478fbe30..83e3e692 100644 --- a/operations/label_change.go +++ b/operations/label_change.go @@ -74,16 +74,16 @@ func (op LabelChangeOperation) Validate() error { return nil } -func NewLabelChangeOperation(author bug.Person, added, removed []bug.Label) LabelChangeOperation { +func NewLabelChangeOperation(author bug.Person, unixTime int64, added, removed []bug.Label) LabelChangeOperation { return LabelChangeOperation{ - OpBase: bug.NewOpBase(bug.LabelChangeOp, author), + OpBase: bug.NewOpBase(bug.LabelChangeOp, author, unixTime), Added: added, Removed: removed, } } // ChangeLabels is a convenience function to apply the operation -func ChangeLabels(b bug.Interface, author bug.Person, add, remove []string) ([]LabelChangeResult, error) { +func ChangeLabels(b bug.Interface, author bug.Person, unixTime int64, add, remove []string) ([]LabelChangeResult, error) { var added, removed []bug.Label var results []LabelChangeResult @@ -131,7 +131,7 @@ func ChangeLabels(b bug.Interface, author bug.Person, add, remove []string) ([]L return results, fmt.Errorf("no label added or removed") } - labelOp := NewLabelChangeOperation(author, added, removed) + labelOp := NewLabelChangeOperation(author, unixTime, added, removed) if err := labelOp.Validate(); err != nil { return nil, err diff --git a/operations/operations_test.go b/operations/operations_test.go index b74dd8d1..b94c2c0c 100644 --- a/operations/operations_test.go +++ b/operations/operations_test.go @@ -2,6 +2,7 @@ package operations import ( "testing" + "time" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/util/git" @@ -13,12 +14,14 @@ func TestValidate(t *testing.T) { Email: "rene@descartes.fr", } + unix := time.Now().Unix() + good := []bug.Operation{ - NewCreateOp(rene, "title", "message", nil), - NewSetTitleOp(rene, "title2", "title1"), - NewAddCommentOp(rene, "message2", nil), - NewSetStatusOp(rene, bug.ClosedStatus), - NewLabelChangeOperation(rene, []bug.Label{"added"}, []bug.Label{"removed"}), + NewCreateOp(rene, unix, "title", "message", nil), + NewSetTitleOp(rene, unix, "title2", "title1"), + NewAddCommentOp(rene, unix, "message2", nil), + NewSetStatusOp(rene, unix, bug.ClosedStatus), + NewLabelChangeOperation(rene, unix, []bug.Label{"added"}, []bug.Label{"removed"}), } for _, op := range good { @@ -29,11 +32,11 @@ func TestValidate(t *testing.T) { bad := []bug.Operation{ // opbase - NewSetStatusOp(bug.Person{Name: "", Email: "rene@descartes.fr"}, bug.ClosedStatus), - NewSetStatusOp(bug.Person{Name: "René Descartes\u001b", Email: "rene@descartes.fr"}, bug.ClosedStatus), - NewSetStatusOp(bug.Person{Name: "René Descartes", Email: "rene@descartes.fr\u001b"}, bug.ClosedStatus), - NewSetStatusOp(bug.Person{Name: "René \nDescartes", Email: "rene@descartes.fr"}, bug.ClosedStatus), - NewSetStatusOp(bug.Person{Name: "René Descartes", Email: "rene@\ndescartes.fr"}, bug.ClosedStatus), + NewSetStatusOp(bug.Person{Name: "", Email: "rene@descartes.fr"}, unix, bug.ClosedStatus), + NewSetStatusOp(bug.Person{Name: "René Descartes\u001b", Email: "rene@descartes.fr"}, unix, bug.ClosedStatus), + NewSetStatusOp(bug.Person{Name: "René Descartes", Email: "rene@descartes.fr\u001b"}, unix, bug.ClosedStatus), + NewSetStatusOp(bug.Person{Name: "René \nDescartes", Email: "rene@descartes.fr"}, unix, bug.ClosedStatus), + NewSetStatusOp(bug.Person{Name: "René Descartes", Email: "rene@\ndescartes.fr"}, unix, bug.ClosedStatus), CreateOperation{OpBase: &bug.OpBase{ Author: rene, UnixTime: 0, @@ -43,21 +46,21 @@ func TestValidate(t *testing.T) { Message: "message", }, - NewCreateOp(rene, "multi\nline", "message", nil), - NewCreateOp(rene, "title", "message", []git.Hash{git.Hash("invalid")}), - NewCreateOp(rene, "title\u001b", "message", nil), - NewCreateOp(rene, "title", "message\u001b", nil), - NewSetTitleOp(rene, "multi\nline", "title1"), - NewSetTitleOp(rene, "title", "multi\nline"), - NewSetTitleOp(rene, "title\u001b", "title2"), - NewSetTitleOp(rene, "title", "title2\u001b"), - NewAddCommentOp(rene, "", nil), - NewAddCommentOp(rene, "message\u001b", nil), - NewAddCommentOp(rene, "message", []git.Hash{git.Hash("invalid")}), - NewSetStatusOp(rene, 1000), - NewSetStatusOp(rene, 0), - NewLabelChangeOperation(rene, []bug.Label{}, []bug.Label{}), - NewLabelChangeOperation(rene, []bug.Label{"multi\nline"}, []bug.Label{}), + NewCreateOp(rene, unix, "multi\nline", "message", nil), + NewCreateOp(rene, unix, "title", "message", []git.Hash{git.Hash("invalid")}), + NewCreateOp(rene, unix, "title\u001b", "message", nil), + NewCreateOp(rene, unix, "title", "message\u001b", nil), + NewSetTitleOp(rene, unix, "multi\nline", "title1"), + NewSetTitleOp(rene, unix, "title", "multi\nline"), + NewSetTitleOp(rene, unix, "title\u001b", "title2"), + NewSetTitleOp(rene, unix, "title", "title2\u001b"), + NewAddCommentOp(rene, unix, "", nil), + NewAddCommentOp(rene, unix, "message\u001b", nil), + NewAddCommentOp(rene, unix, "message", []git.Hash{git.Hash("invalid")}), + NewSetStatusOp(rene, unix, 1000), + NewSetStatusOp(rene, unix, 0), + NewLabelChangeOperation(rene, unix, []bug.Label{}, []bug.Label{}), + NewLabelChangeOperation(rene, unix, []bug.Label{"multi\nline"}, []bug.Label{}), } for i, op := range bad { diff --git a/operations/set_status.go b/operations/set_status.go index 6ef95320..3e7eae4a 100644 --- a/operations/set_status.go +++ b/operations/set_status.go @@ -32,16 +32,16 @@ func (op SetStatusOperation) Validate() error { return nil } -func NewSetStatusOp(author bug.Person, status bug.Status) SetStatusOperation { +func NewSetStatusOp(author bug.Person, unixTime int64, status bug.Status) SetStatusOperation { return SetStatusOperation{ - OpBase: bug.NewOpBase(bug.SetStatusOp, author), + OpBase: bug.NewOpBase(bug.SetStatusOp, author, unixTime), Status: status, } } // Convenience function to apply the operation -func Open(b bug.Interface, author bug.Person) error { - op := NewSetStatusOp(author, bug.OpenStatus) +func Open(b bug.Interface, author bug.Person, unixTime int64) error { + op := NewSetStatusOp(author, unixTime, bug.OpenStatus) if err := op.Validate(); err != nil { return err } @@ -50,8 +50,8 @@ func Open(b bug.Interface, author bug.Person) error { } // Convenience function to apply the operation -func Close(b bug.Interface, author bug.Person) error { - op := NewSetStatusOp(author, bug.ClosedStatus) +func Close(b bug.Interface, author bug.Person, unixTime int64) error { + op := NewSetStatusOp(author, unixTime, bug.ClosedStatus) if err := op.Validate(); err != nil { return err } diff --git a/operations/set_title.go b/operations/set_title.go index 154998cf..e6964a65 100644 --- a/operations/set_title.go +++ b/operations/set_title.go @@ -52,16 +52,16 @@ func (op SetTitleOperation) Validate() error { return nil } -func NewSetTitleOp(author bug.Person, title string, was string) SetTitleOperation { +func NewSetTitleOp(author bug.Person, unixTime int64, title string, was string) SetTitleOperation { return SetTitleOperation{ - OpBase: bug.NewOpBase(bug.SetTitleOp, author), + OpBase: bug.NewOpBase(bug.SetTitleOp, author, unixTime), Title: title, Was: was, } } // Convenience function to apply the operation -func SetTitle(b bug.Interface, author bug.Person, title string) error { +func SetTitle(b bug.Interface, author bug.Person, unixTime int64, title string) error { it := bug.NewOperationIterator(b) var lastTitleOp bug.Operation @@ -79,7 +79,7 @@ func SetTitle(b bug.Interface, author bug.Person, title string) error { was = b.FirstOp().(CreateOperation).Title } - setTitleOp := NewSetTitleOp(author, title, was) + setTitleOp := NewSetTitleOp(author, unixTime, title, was) if err := setTitleOp.Validate(); err != nil { return err |