set_status.go

 1package operations
 2
 3import (
 4	"github.com/MichaelMure/git-bug/bug"
 5)
 6
 7// SetStatusOperation will change the status of a bug
 8
 9var _ bug.Operation = SetStatusOperation{}
10
11type SetStatusOperation struct {
12	bug.OpBase
13	Status bug.Status `json:"status"`
14}
15
16func (op SetStatusOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
17	snapshot.Status = op.Status
18
19	return snapshot
20}
21
22func NewSetStatusOp(author bug.Person, status bug.Status) SetStatusOperation {
23	return SetStatusOperation{
24		OpBase: bug.NewOpBase(bug.SetStatusOp, author),
25		Status: status,
26	}
27}
28
29// Convenience function to apply the operation
30func Open(b bug.Interface, author bug.Person) {
31	op := NewSetStatusOp(author, bug.OpenStatus)
32	b.Append(op)
33}
34
35// Convenience function to apply the operation
36func Close(b bug.Interface, author bug.Person) {
37	op := NewSetStatusOp(author, bug.ClosedStatus)
38	b.Append(op)
39}