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-09-11 23:04:16 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/git"
|
2018-07-14 23:18:40 +03:00
|
|
|
)
|
2018-07-13 23:53:53 +03:00
|
|
|
|
2018-07-18 01:16:06 +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-08-06 21:31:20 +03:00
|
|
|
// TODO: change for a map[string]util.hash to store the filename ?
|
2018-09-11 23:04:16 +03:00
|
|
|
files []git.Hash
|
2018-07-13 23:53:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
|
|
|
|
comment := bug.Comment{
|
2018-07-18 01:16:06 +03:00
|
|
|
Message: op.Message,
|
|
|
|
Author: op.Author,
|
2018-08-03 00:37:49 +03:00
|
|
|
Files: op.files,
|
2018-09-10 20:03:17 +03:00
|
|
|
UnixTime: op.UnixTime,
|
2018-07-13 23:53:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
snapshot.Comments = append(snapshot.Comments, comment)
|
|
|
|
|
|
|
|
return snapshot
|
|
|
|
}
|
2018-07-25 19:01:32 +03:00
|
|
|
|
2018-09-11 23:04:16 +03:00
|
|
|
func (op AddCommentOperation) Files() []git.Hash {
|
2018-08-03 00:37:49 +03:00
|
|
|
return op.files
|
|
|
|
}
|
|
|
|
|
2018-09-11 23:04:16 +03:00
|
|
|
func NewAddCommentOp(author bug.Person, message string, files []git.Hash) AddCommentOperation {
|
2018-07-25 22:25:26 +03:00
|
|
|
return AddCommentOperation{
|
|
|
|
OpBase: bug.NewOpBase(bug.AddCommentOp, author),
|
|
|
|
Message: message,
|
2018-08-03 00:37:49 +03:00
|
|
|
files: files,
|
2018-07-25 22:25:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience function to apply the operation
|
2018-08-23 20:11:38 +03:00
|
|
|
func Comment(b bug.Interface, author bug.Person, message string) {
|
2018-08-03 00:37:49 +03:00
|
|
|
CommentWithFiles(b, author, message, nil)
|
|
|
|
}
|
|
|
|
|
2018-09-11 23:04:16 +03:00
|
|
|
func CommentWithFiles(b bug.Interface, author bug.Person, message string, files []git.Hash) {
|
2018-08-03 00:37:49 +03:00
|
|
|
addCommentOp := NewAddCommentOp(author, message, files)
|
2018-07-25 19:01:32 +03:00
|
|
|
b.Append(addCommentOp)
|
|
|
|
}
|