1package operations
2
3import (
4 "github.com/MichaelMure/git-bug/bug"
5 "reflect"
6 "time"
7)
8
9// CreateOperation define the initial creation of a bug
10
11var _ bug.Operation = CreateOperation{}
12
13type CreateOperation struct {
14 bug.OpBase
15 Title string
16 Message string
17 Author bug.Person
18 Time time.Time
19}
20
21func NewCreateOp(author bug.Person, title, message string) CreateOperation {
22 return CreateOperation{
23 OpBase: bug.OpBase{OperationType: bug.CREATE},
24 Title: title,
25 Message: message,
26 Author: author,
27 Time: time.Now(),
28 }
29}
30
31func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
32 empty := bug.Snapshot{}
33
34 if !reflect.DeepEqual(snapshot, empty) {
35 panic("Create operation should never be applied on a non-empty snapshot")
36 }
37
38 snapshot.Title = op.Title
39 snapshot.Comments = []bug.Comment{
40 {
41 Message: op.Message,
42 Author: op.Author,
43 Time: op.Time,
44 },
45 }
46 return snapshot
47}