set_status.go

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