1package bug
2
3import "github.com/MichaelMure/git-bug/util/git"
4
5type TimelineItem interface {
6 // Hash return the hash of the item
7 Hash() (git.Hash, error)
8}
9
10// CreateTimelineItem replace a Create operation in the Timeline and hold its edition history
11type CreateTimelineItem struct {
12 hash git.Hash
13 History []Comment
14}
15
16func NewCreateTimelineItem(hash git.Hash, comment Comment) *CreateTimelineItem {
17 return &CreateTimelineItem{
18 hash: hash,
19 History: []Comment{
20 comment,
21 },
22 }
23}
24
25func (c *CreateTimelineItem) Hash() (git.Hash, error) {
26 return c.hash, nil
27}
28
29func (c *CreateTimelineItem) LastState() Comment {
30 if len(c.History) == 0 {
31 panic("no history yet")
32 }
33
34 return c.History[len(c.History)-1]
35}
36
37// CommentTimelineItem replace a Comment in the Timeline and hold its edition history
38type CommentTimelineItem struct {
39 hash git.Hash
40 History []Comment
41}
42
43func NewCommentTimelineItem(hash git.Hash, comment Comment) *CommentTimelineItem {
44 return &CommentTimelineItem{
45 hash: hash,
46 History: []Comment{
47 comment,
48 },
49 }
50}
51
52func (c *CommentTimelineItem) Hash() (git.Hash, error) {
53 return c.hash, nil
54}
55
56func (c *CommentTimelineItem) LastState() Comment {
57 if len(c.History) == 0 {
58 panic("no history yet")
59 }
60
61 return c.History[len(c.History)-1]
62}