add_comment.go

 1package operations
 2
 3import (
 4	"github.com/MichaelMure/git-bug/bug"
 5)
 6
 7// AddCommentOperation will add a new comment in the bug
 8
 9var _ bug.Operation = AddCommentOperation{}
10
11type AddCommentOperation struct {
12	bug.OpBase
13	Message string
14}
15
16func NewAddCommentOp(author bug.Person, message string) AddCommentOperation {
17	return AddCommentOperation{
18		OpBase:  bug.NewOpBase(bug.AddCommentOp, author),
19		Message: message,
20	}
21}
22
23func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
24	comment := bug.Comment{
25		Message:  op.Message,
26		Author:   op.Author,
27		UnixTime: op.UnixTime,
28	}
29
30	snapshot.Comments = append(snapshot.Comments, comment)
31
32	return snapshot
33}