From 55aef8c38773a7cce39a5e154f8221a4b817ac04 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 13 Jul 2018 22:53:53 +0200 Subject: implement AddComment --- bug/operations/add_comment.go | 30 ++++++++++++++++++++++++++++++ bug/operations/create.go | 4 ---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 bug/operations/add_comment.go (limited to 'bug') diff --git a/bug/operations/add_comment.go b/bug/operations/add_comment.go new file mode 100644 index 00000000..2b83de83 --- /dev/null +++ b/bug/operations/add_comment.go @@ -0,0 +1,30 @@ +package operations + +import "github.com/MichaelMure/git-bug/bug" + +var _ bug.Operation = AddCommentOperation{} + +type AddCommentOperation struct { + bug.OpBase + Message string `json:"m"` + Author bug.Person `json:"a"` +} + +func NewAddCommentOp(author bug.Person, message string) AddCommentOperation { + return AddCommentOperation{ + OpBase: bug.OpBase{OperationType: bug.ADD_COMMENT}, + Message: message, + Author: author, + } +} + +func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { + comment := bug.Comment{ + Message: op.Message, + Author: op.Author, + } + + snapshot.Comments = append(snapshot.Comments, comment) + + return snapshot +} diff --git a/bug/operations/create.go b/bug/operations/create.go index 9911ee89..1c34f85d 100644 --- a/bug/operations/create.go +++ b/bug/operations/create.go @@ -25,10 +25,6 @@ func NewCreateOp(author bug.Person, title, message string) CreateOperation { } } -//func (op CreateOperation) OpType() bug.OperationType { -// return bug.CREATE -//} - func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { empty := bug.Snapshot{} -- cgit