implement AddComment

This commit is contained in:
Michael Muré 2018-07-13 22:53:53 +02:00
parent 35d64e4f9e
commit 55aef8c387
No known key found for this signature in database
GPG Key ID: A4457C029293126F
5 changed files with 35 additions and 13 deletions

View File

@ -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
}

View File

@ -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 { func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
empty := bug.Snapshot{} empty := bug.Snapshot{}

View File

@ -12,10 +12,6 @@ import (
"strings" "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. // GitRepo represents an instance of a (local) git repository.
type GitRepo struct { type GitRepo struct {
Path string Path string
@ -29,8 +25,6 @@ func (repo *GitRepo) runGitCommandWithIO(stdin io.Reader, stdout, stderr io.Writ
cmd.Stdout = stdout cmd.Stdout = stdout
cmd.Stderr = stderr cmd.Stderr = stderr
//cmd.Env = append(cmd.Env, gitEnvConfig)
return cmd.Run() return cmd.Run()
} }

View File

@ -13,9 +13,10 @@ var (
Email: "rene@descartes.fr", Email: "rene@descartes.fr",
} }
createOp = operations.NewCreateOp(rene, "title", "message") createOp = operations.NewCreateOp(rene, "title", "message")
setTitleOp = operations.NewSetTitleOp("title2") setTitleOp = operations.NewSetTitleOp("title2")
mockRepo = repository.NewMockRepoForTest() addCommentOp = operations.NewAddCommentOp(rene, "message2")
mockRepo = repository.NewMockRepoForTest()
) )
func TestOpIterator(t *testing.T) { func TestOpIterator(t *testing.T) {

View File

@ -13,6 +13,7 @@ func TestOperationPackSerialize(t *testing.T) {
opp.Append(createOp) opp.Append(createOp)
opp.Append(setTitleOp) opp.Append(setTitleOp)
opp.Append(addCommentOp)
jsonBytes, err := opp.Serialize() jsonBytes, err := opp.Serialize()