diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-30 11:10:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-30 11:10:03 +0200 |
commit | d71bb7dd7632780cf5aad5fda84027fa03a9d0f0 (patch) | |
tree | dba6c3c0bab18f41e21cd36a9fe05d1d27a574d4 /bug/op_set_status.go | |
parent | 8fdd6bf99c111c3756056e87ffd9209875ac5c1f (diff) | |
parent | bad9cda969b49bf1bce6799056476ac4684892df (diff) | |
download | git-bug-d71bb7dd7632780cf5aad5fda84027fa03a9d0f0.tar.gz |
Merge pull request #54 from MichaelMure/editablecomment
Core support for editable comments
Diffstat (limited to 'bug/op_set_status.go')
-rw-r--r-- | bug/op_set_status.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/bug/op_set_status.go b/bug/op_set_status.go new file mode 100644 index 00000000..cdfa25e7 --- /dev/null +++ b/bug/op_set_status.go @@ -0,0 +1,66 @@ +package bug + +import ( + "github.com/MichaelMure/git-bug/util/git" + "github.com/pkg/errors" +) + +var _ Operation = &SetStatusOperation{} + +// SetStatusOperation will change the status of a bug +type SetStatusOperation struct { + *OpBase + Status Status `json:"status"` +} + +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.Status = op.Status + snapshot.Timeline = append(snapshot.Timeline, op) +} + +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 +} |