git-bug/bug/operations/add_comment.go

40 lines
860 B
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"
)
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
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,
UnixTime: op.UnixTime,
2018-07-13 23:53:53 +03:00
}
snapshot.Comments = append(snapshot.Comments, comment)
return snapshot
}
2018-07-25 22:25:26 +03:00
func NewAddCommentOp(author bug.Person, message string) AddCommentOperation {
return AddCommentOperation{
OpBase: bug.NewOpBase(bug.AddCommentOp, author),
Message: message,
}
}
// Convenience function to apply the operation
func Comment(b *bug.Bug, author bug.Person, message string) {
addCommentOp := NewAddCommentOp(author, message)
b.Append(addCommentOp)
}