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 (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
17 comment := bug.Comment{
18 Message: op.Message,
19 Author: op.Author,
20 UnixTime: op.UnixTime,
21 }
22
23 snapshot.Comments = append(snapshot.Comments, comment)
24
25 return snapshot
26}
27
28func NewAddCommentOp(author bug.Person, message string) AddCommentOperation {
29 return AddCommentOperation{
30 OpBase: bug.NewOpBase(bug.AddCommentOp, author),
31 Message: message,
32 }
33}
34
35// Convenience function to apply the operation
36func Comment(b *bug.Bug, author bug.Person, message string) {
37 addCommentOp := NewAddCommentOp(author, message)
38 b.Append(addCommentOp)
39}