forked from MichaelMure/git-bug
-
Notifications
You must be signed in to change notification settings - Fork 3
/
timeline.go
59 lines (50 loc) · 1.44 KB
/
timeline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package bug
import (
"fmt"
termtext "github.com/MichaelMure/go-term-text"
"github.com/daedaleanai/git-ticket/entity"
"github.com/daedaleanai/git-ticket/identity"
"github.com/daedaleanai/git-ticket/repository"
"github.com/daedaleanai/git-ticket/util/timestamp"
)
type TimelineItem interface {
// ID return the identifier of the item
Id() entity.Id
// When returns the time of the item
When() timestamp.Timestamp
// Timeline specific print message
String() string
}
// CommentTimelineItem is a TimelineItem that holds a Comment and its edition history
type CommentTimelineItem struct {
id entity.Id
Index int
Author identity.Interface
Message string
Files []repository.Hash
CreatedAt timestamp.Timestamp
}
const timelineDisplayNameWidth = 15
const timelineCommentOffset = 39
func NewCommentTimelineItem(ID entity.Id, index int, comment Comment) CommentTimelineItem {
return CommentTimelineItem{
id: ID,
Index: index,
Author: comment.Author,
Message: comment.Message,
Files: comment.Files,
CreatedAt: comment.UnixTime,
}
}
func (c *CommentTimelineItem) Id() entity.Id {
return c.id
}
func (c CommentTimelineItem) When() timestamp.Timestamp {
return c.CreatedAt
}
func (c CommentTimelineItem) String() string {
return fmt.Sprintf("(%s) %s: %s",
c.CreatedAt.Time().Format("2006-01-02 15:04:05"),
termtext.LeftPadMaxLine(c.Author.DisplayName(), timelineDisplayNameWidth, 0),
c.Message)
}