add_comment.go

 1package operations
 2
 3import (
 4	"github.com/MichaelMure/git-bug/bug"
 5	"github.com/MichaelMure/git-bug/util"
 6)
 7
 8// AddCommentOperation will add a new comment in the bug
 9
10var _ bug.Operation = AddCommentOperation{}
11
12type AddCommentOperation struct {
13	bug.OpBase
14	Message string
15	files   []util.Hash
16}
17
18func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
19	comment := bug.Comment{
20		Message:  op.Message,
21		Author:   op.Author,
22		Files:    op.files,
23		UnixTime: op.UnixTime,
24	}
25
26	snapshot.Comments = append(snapshot.Comments, comment)
27
28	return snapshot
29}
30
31func (op AddCommentOperation) Files() []util.Hash {
32	return op.files
33}
34
35func NewAddCommentOp(author bug.Person, message string, files []util.Hash) AddCommentOperation {
36	return AddCommentOperation{
37		OpBase:  bug.NewOpBase(bug.AddCommentOp, author),
38		Message: message,
39		files:   files,
40	}
41}
42
43// Convenience function to apply the operation
44func Comment(b *bug.Bug, author bug.Person, message string) {
45	CommentWithFiles(b, author, message, nil)
46}
47
48func CommentWithFiles(b *bug.Bug, author bug.Person, message string, files []util.Hash) {
49	addCommentOp := NewAddCommentOp(author, message, files)
50	b.Append(addCommentOp)
51}