git-bug/bug/operations/add_comment.go

53 lines
1.2 KiB
Go
Raw Normal View History

2018-07-13 23:53:53 +03:00
package operations
2018-07-14 23:18:40 +03:00
import (
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/util"
2018-07-14 23:18:40 +03:00
)
2018-07-13 23:53:53 +03:00
// AddCommentOperation will add a new comment in the bug
2018-07-13 23:53:53 +03:00
var _ bug.Operation = AddCommentOperation{}
type AddCommentOperation struct {
bug.OpBase
2018-07-14 23:18:40 +03:00
Message string
// TODO: change for a map[string]util.hash to store the filename ?
files []util.Hash
2018-07-13 23:53:53 +03:00
}
func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
comment := bug.Comment{
Message: op.Message,
Author: op.Author,
Files: op.files,
UnixTime: op.UnixTime(),
2018-07-13 23:53:53 +03:00
}
snapshot.Comments = append(snapshot.Comments, comment)
return snapshot
}
func (op AddCommentOperation) Files() []util.Hash {
return op.files
}
func NewAddCommentOp(author bug.Person, message string, files []util.Hash) AddCommentOperation {
2018-07-25 22:25:26 +03:00
return AddCommentOperation{
OpBase: bug.NewOpBase(bug.AddCommentOp, author),
Message: message,
files: files,
2018-07-25 22:25:26 +03:00
}
}
// Convenience function to apply the operation
func Comment(b bug.Interface, author bug.Person, message string) {
CommentWithFiles(b, author, message, nil)
}
func CommentWithFiles(b bug.Interface, author bug.Person, message string, files []util.Hash) {
addCommentOp := NewAddCommentOp(author, message, files)
b.Append(addCommentOp)
}