From 1bf268cebc84a9de1e538cbb54bcc0f434022192 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 28 Sep 2018 20:39:39 +0200 Subject: merge package operations into bug, they are tightly coupled anyway --- bug/op_set_status.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bug/op_set_status.go (limited to 'bug/op_set_status.go') diff --git a/bug/op_set_status.go b/bug/op_set_status.go new file mode 100644 index 00000000..d6df3da4 --- /dev/null +++ b/bug/op_set_status.go @@ -0,0 +1,63 @@ +package bug + +import ( + "github.com/pkg/errors" +) + +// SetStatusOperation will change the status of a bug + +var _ Operation = SetStatusOperation{} + +type SetStatusOperation struct { + *OpBase + Status Status `json:"status"` +} + +func (op SetStatusOperation) base() *OpBase { + return op.OpBase +} + +func (op SetStatusOperation) Apply(snapshot Snapshot) Snapshot { + snapshot.Status = op.Status + + return snapshot +} + +func (op SetStatusOperation) Validate() error { + if err := opBaseValidate(op, SetStatusOp); err != nil { + return err + } + + if err := op.Status.Validate(); err != nil { + return errors.Wrap(err, "status") + } + + return nil +} + +func NewSetStatusOp(author Person, unixTime int64, status Status) SetStatusOperation { + return SetStatusOperation{ + OpBase: newOpBase(SetStatusOp, author, unixTime), + Status: status, + } +} + +// Convenience function to apply the operation +func Open(b Interface, author Person, unixTime int64) error { + op := NewSetStatusOp(author, unixTime, OpenStatus) + if err := op.Validate(); err != nil { + return err + } + b.Append(op) + return nil +} + +// Convenience function to apply the operation +func Close(b Interface, author Person, unixTime int64) error { + op := NewSetStatusOp(author, unixTime, ClosedStatus) + if err := op.Validate(); err != nil { + return err + } + b.Append(op) + return nil +} -- cgit From 794d014fae9a78bd8664e6628a20902bd6dc767a Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 28 Sep 2018 23:51:47 +0200 Subject: bug: define a hash-based identifier for an operation --- bug/op_set_status.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'bug/op_set_status.go') diff --git a/bug/op_set_status.go b/bug/op_set_status.go index d6df3da4..19af46c2 100644 --- a/bug/op_set_status.go +++ b/bug/op_set_status.go @@ -1,6 +1,7 @@ package bug import ( + "github.com/MichaelMure/git-bug/util/git" "github.com/pkg/errors" ) @@ -17,6 +18,10 @@ func (op SetStatusOperation) base() *OpBase { return op.OpBase } +func (op SetStatusOperation) Hash() (git.Hash, error) { + return hashOperation(op) +} + func (op SetStatusOperation) Apply(snapshot Snapshot) Snapshot { snapshot.Status = op.Status -- cgit From 41e61a67b63e4d6c517005cf6f427115a664bdb5 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 29 Sep 2018 11:28:18 +0200 Subject: bug: apply an operation with a pointer to the snapshot --- bug/op_set_status.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'bug/op_set_status.go') diff --git a/bug/op_set_status.go b/bug/op_set_status.go index 19af46c2..1fb9cab6 100644 --- a/bug/op_set_status.go +++ b/bug/op_set_status.go @@ -22,10 +22,8 @@ func (op SetStatusOperation) Hash() (git.Hash, error) { return hashOperation(op) } -func (op SetStatusOperation) Apply(snapshot Snapshot) Snapshot { +func (op SetStatusOperation) Apply(snapshot *Snapshot) { snapshot.Status = op.Status - - return snapshot } func (op SetStatusOperation) Validate() error { -- cgit From c46d01f8c10e6363b680fa6876e91bd8eaf3bb3e Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 29 Sep 2018 20:41:19 +0200 Subject: bug: implement comment edition - add a new operation - add a new "timeline" in the snapshot that hold a processed version of the operations --- bug/op_set_status.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'bug/op_set_status.go') diff --git a/bug/op_set_status.go b/bug/op_set_status.go index 1fb9cab6..cdfa25e7 100644 --- a/bug/op_set_status.go +++ b/bug/op_set_status.go @@ -5,28 +5,28 @@ import ( "github.com/pkg/errors" ) -// SetStatusOperation will change the status of a bug - -var _ Operation = SetStatusOperation{} +var _ Operation = &SetStatusOperation{} +// SetStatusOperation will change the status of a bug type SetStatusOperation struct { *OpBase Status Status `json:"status"` } -func (op SetStatusOperation) base() *OpBase { +func (op *SetStatusOperation) base() *OpBase { return op.OpBase } -func (op SetStatusOperation) Hash() (git.Hash, error) { +func (op *SetStatusOperation) Hash() (git.Hash, error) { return hashOperation(op) } -func (op SetStatusOperation) Apply(snapshot *Snapshot) { +func (op *SetStatusOperation) Apply(snapshot *Snapshot) { snapshot.Status = op.Status + snapshot.Timeline = append(snapshot.Timeline, op) } -func (op SetStatusOperation) Validate() error { +func (op *SetStatusOperation) Validate() error { if err := opBaseValidate(op, SetStatusOp); err != nil { return err } @@ -38,8 +38,8 @@ func (op SetStatusOperation) Validate() error { return nil } -func NewSetStatusOp(author Person, unixTime int64, status Status) SetStatusOperation { - return SetStatusOperation{ +func NewSetStatusOp(author Person, unixTime int64, status Status) *SetStatusOperation { + return &SetStatusOperation{ OpBase: newOpBase(SetStatusOp, author, unixTime), Status: status, } -- cgit