aboutsummaryrefslogtreecommitdiffstats
path: root/operations/add_comment.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-11 22:04:16 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-11 22:14:46 +0200
commit3605887345792d2f981f971c6c4a2cb7f86a343e (patch)
treeafd525b6e3a638e4c619a5a986fcb2811c297444 /operations/add_comment.go
parent7b05983c19af4da70f2a9a5062913f4e4f5d5faa (diff)
downloadgit-bug-3605887345792d2f981f971c6c4a2cb7f86a343e.tar.gz
reorganize package for a more idomatic go
Diffstat (limited to 'operations/add_comment.go')
-rw-r--r--operations/add_comment.go52
1 files changed, 52 insertions, 0 deletions
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)
+}