aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-13 22:53:53 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-13 22:53:53 +0200
commit55aef8c38773a7cce39a5e154f8221a4b817ac04 (patch)
tree6fb23c7f099a69c9abfdca7f05fee108f3ec6786
parent35d64e4f9e3e0a0ffd041e430a64650bb8ea71fa (diff)
downloadgit-bug-55aef8c38773a7cce39a5e154f8221a4b817ac04.tar.gz
implement AddComment
-rw-r--r--bug/operations/add_comment.go30
-rw-r--r--bug/operations/create.go4
-rw-r--r--repository/git.go6
-rw-r--r--tests/operation_iterator_test.go7
-rw-r--r--tests/operation_pack_test.go1
5 files changed, 35 insertions, 13 deletions
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{}
diff --git a/repository/git.go b/repository/git.go
index 92c7bb63..a55e451c 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -12,10 +12,6 @@ import (
"strings"
)
-// This is used to have a different staging area than the regular git index
-// when creating data in git
-const gitEnvConfig = "GIT_INDEX_FILE=BUG_STAGING_INDEX"
-
// GitRepo represents an instance of a (local) git repository.
type GitRepo struct {
Path string
@@ -29,8 +25,6 @@ func (repo *GitRepo) runGitCommandWithIO(stdin io.Reader, stdout, stderr io.Writ
cmd.Stdout = stdout
cmd.Stderr = stderr
- //cmd.Env = append(cmd.Env, gitEnvConfig)
-
return cmd.Run()
}
diff --git a/tests/operation_iterator_test.go b/tests/operation_iterator_test.go
index b2f01513..03747fa4 100644
--- a/tests/operation_iterator_test.go
+++ b/tests/operation_iterator_test.go
@@ -13,9 +13,10 @@ var (
Email: "rene@descartes.fr",
}
- createOp = operations.NewCreateOp(rene, "title", "message")
- setTitleOp = operations.NewSetTitleOp("title2")
- mockRepo = repository.NewMockRepoForTest()
+ createOp = operations.NewCreateOp(rene, "title", "message")
+ setTitleOp = operations.NewSetTitleOp("title2")
+ addCommentOp = operations.NewAddCommentOp(rene, "message2")
+ mockRepo = repository.NewMockRepoForTest()
)
func TestOpIterator(t *testing.T) {
diff --git a/tests/operation_pack_test.go b/tests/operation_pack_test.go
index 8ca43c09..2b19e364 100644
--- a/tests/operation_pack_test.go
+++ b/tests/operation_pack_test.go
@@ -13,6 +13,7 @@ func TestOperationPackSerialize(t *testing.T) {
opp.Append(createOp)
opp.Append(setTitleOp)
+ opp.Append(addCommentOp)
jsonBytes, err := opp.Serialize()