aboutsummaryrefslogtreecommitdiffstats
path: root/bug/op_add_comment.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-29 20:41:19 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-29 20:41:19 +0200
commitc46d01f8c10e6363b680fa6876e91bd8eaf3bb3e (patch)
treedde41c1253534bf4ff36e39454f2bdbdf4b9590f /bug/op_add_comment.go
parent41e61a67b63e4d6c517005cf6f427115a664bdb5 (diff)
downloadgit-bug-c46d01f8c10e6363b680fa6876e91bd8eaf3bb3e.tar.gz
bug: implement comment edition
- add a new operation - add a new "timeline" in the snapshot that hold a processed version of the operations
Diffstat (limited to 'bug/op_add_comment.go')
-rw-r--r--bug/op_add_comment.go28
1 files changed, 18 insertions, 10 deletions
diff --git a/bug/op_add_comment.go b/bug/op_add_comment.go
index e5622073..4594ba70 100644
--- a/bug/op_add_comment.go
+++ b/bug/op_add_comment.go
@@ -7,10 +7,9 @@ import (
"github.com/MichaelMure/git-bug/util/text"
)
-// AddCommentOperation will add a new comment in the bug
-
-var _ Operation = AddCommentOperation{}
+var _ Operation = &AddCommentOperation{}
+// AddCommentOperation will add a new comment in the bug
type AddCommentOperation struct {
*OpBase
Message string `json:"message"`
@@ -18,15 +17,15 @@ type AddCommentOperation struct {
Files []git.Hash `json:"files"`
}
-func (op AddCommentOperation) base() *OpBase {
+func (op *AddCommentOperation) base() *OpBase {
return op.OpBase
}
-func (op AddCommentOperation) Hash() (git.Hash, error) {
+func (op *AddCommentOperation) Hash() (git.Hash, error) {
return hashOperation(op)
}
-func (op AddCommentOperation) Apply(snapshot *Snapshot) {
+func (op *AddCommentOperation) Apply(snapshot *Snapshot) {
comment := Comment{
Message: op.Message,
Author: op.Author,
@@ -35,13 +34,22 @@ func (op AddCommentOperation) Apply(snapshot *Snapshot) {
}
snapshot.Comments = append(snapshot.Comments, comment)
+
+ hash, err := op.Hash()
+ if err != nil {
+ // Should never error unless a programming error happened
+ // (covered in OpBase.Validate())
+ panic(err)
+ }
+
+ snapshot.Timeline = append(snapshot.Timeline, NewCommentTimelineItem(hash, comment))
}
-func (op AddCommentOperation) GetFiles() []git.Hash {
+func (op *AddCommentOperation) GetFiles() []git.Hash {
return op.Files
}
-func (op AddCommentOperation) Validate() error {
+func (op *AddCommentOperation) Validate() error {
if err := opBaseValidate(op, AddCommentOp); err != nil {
return err
}
@@ -57,8 +65,8 @@ func (op AddCommentOperation) Validate() error {
return nil
}
-func NewAddCommentOp(author Person, unixTime int64, message string, files []git.Hash) AddCommentOperation {
- return AddCommentOperation{
+func NewAddCommentOp(author Person, unixTime int64, message string, files []git.Hash) *AddCommentOperation {
+ return &AddCommentOperation{
OpBase: newOpBase(AddCommentOp, author, unixTime),
Message: message,
Files: files,