From 3605887345792d2f981f971c6c4a2cb7f86a343e Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Tue, 11 Sep 2018 22:04:16 +0200 Subject: reorganize package for a more idomatic go --- operations/add_comment.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 operations/add_comment.go (limited to 'operations/add_comment.go') diff --git a/operations/add_comment.go b/operations/add_comment.go new file mode 100644 index 00000000..24fa2696 --- /dev/null +++ b/operations/add_comment.go @@ -0,0 +1,52 @@ +package operations + +import ( + "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/util/git" +) + +// AddCommentOperation will add a new comment in the bug + +var _ bug.Operation = AddCommentOperation{} + +type AddCommentOperation struct { + bug.OpBase + Message string + // TODO: change for a map[string]util.hash to store the filename ? + files []git.Hash +} + +func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { + comment := bug.Comment{ + Message: op.Message, + Author: op.Author, + Files: op.files, + UnixTime: op.UnixTime, + } + + snapshot.Comments = append(snapshot.Comments, comment) + + return snapshot +} + +func (op AddCommentOperation) Files() []git.Hash { + return op.files +} + +func NewAddCommentOp(author bug.Person, message string, files []git.Hash) AddCommentOperation { + return AddCommentOperation{ + OpBase: bug.NewOpBase(bug.AddCommentOp, author), + Message: message, + files: files, + } +} + +// Convenience function to apply the operation +func Comment(b bug.Interface, author bug.Person, message string) { + CommentWithFiles(b, author, message, nil) +} + +func CommentWithFiles(b bug.Interface, author bug.Person, message string, files []git.Hash) { + addCommentOp := NewAddCommentOp(author, message, files) + b.Append(addCommentOp) +} -- cgit