aboutsummaryrefslogtreecommitdiffstats
path: root/bug/op_create.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_create.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_create.go')
-rw-r--r--bug/op_create.go43
1 files changed, 27 insertions, 16 deletions
diff --git a/bug/op_create.go b/bug/op_create.go
index 70ca7242..5c41eb7c 100644
--- a/bug/op_create.go
+++ b/bug/op_create.go
@@ -8,10 +8,9 @@ import (
"github.com/MichaelMure/git-bug/util/text"
)
-// CreateOperation define the initial creation of a bug
-
-var _ Operation = CreateOperation{}
+var _ Operation = &CreateOperation{}
+// CreateOperation define the initial creation of a bug
type CreateOperation struct {
*OpBase
Title string `json:"title"`
@@ -19,32 +18,44 @@ type CreateOperation struct {
Files []git.Hash `json:"files"`
}
-func (op CreateOperation) base() *OpBase {
+func (op *CreateOperation) base() *OpBase {
return op.OpBase
}
-func (op CreateOperation) Hash() (git.Hash, error) {
+func (op *CreateOperation) Hash() (git.Hash, error) {
return hashOperation(op)
}
-func (op CreateOperation) Apply(snapshot *Snapshot) {
+func (op *CreateOperation) Apply(snapshot *Snapshot) {
snapshot.Title = op.Title
- snapshot.Comments = []Comment{
- {
- Message: op.Message,
- Author: op.Author,
- UnixTime: op.UnixTime,
- },
+
+ comment := Comment{
+ Message: op.Message,
+ Author: op.Author,
+ UnixTime: op.UnixTime,
}
+
+ snapshot.Comments = []Comment{comment}
snapshot.Author = op.Author
snapshot.CreatedAt = op.Time()
+
+ hash, err := op.Hash()
+ if err != nil {
+ // Should never error unless a programming error happened
+ // (covered in OpBase.Validate())
+ panic(err)
+ }
+
+ snapshot.Timeline = []TimelineItem{
+ NewCreateTimelineItem(hash, comment),
+ }
}
-func (op CreateOperation) GetFiles() []git.Hash {
+func (op *CreateOperation) GetFiles() []git.Hash {
return op.Files
}
-func (op CreateOperation) Validate() error {
+func (op *CreateOperation) Validate() error {
if err := opBaseValidate(op, CreateOp); err != nil {
return err
}
@@ -68,8 +79,8 @@ func (op CreateOperation) Validate() error {
return nil
}
-func NewCreateOp(author Person, unixTime int64, title, message string, files []git.Hash) CreateOperation {
- return CreateOperation{
+func NewCreateOp(author Person, unixTime int64, title, message string, files []git.Hash) *CreateOperation {
+ return &CreateOperation{
OpBase: newOpBase(CreateOp, author, unixTime),
Title: title,
Message: message,