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