1package bug
2
3import (
4 "github.com/MichaelMure/git-bug/identity"
5 "github.com/MichaelMure/git-bug/util/git"
6 "github.com/MichaelMure/git-bug/util/timestamp"
7 "github.com/dustin/go-humanize"
8)
9
10// Comment represent a comment in a Bug
11type Comment struct {
12 id string
13 Author identity.Interface
14 Message string
15 Files []git.Hash
16
17 // Creation time of the comment.
18 // Should be used only for human display, never for ordering as we can't rely on it in a distributed system.
19 UnixTime timestamp.Timestamp
20}
21
22// Id return the Comment identifier
23func (c Comment) Id() string {
24 if c.id == "" {
25 // simply panic as it would be a coding error
26 // (using an id of an identity not stored yet)
27 panic("no id yet")
28 }
29 return c.id
30}
31
32// HumanId return the Comment identifier truncated for human consumption
33func (c Comment) HumanId() string {
34 return FormatHumanID(c.Id())
35}
36
37// FormatTimeRel format the UnixTime of the comment for human consumption
38func (c Comment) FormatTimeRel() string {
39 return humanize.Time(c.UnixTime.Time())
40}
41
42func (c Comment) FormatTime() string {
43 return c.UnixTime.Time().Format("Mon Jan 2 15:04:05 2006 +0200")
44}
45
46// Sign post method for gqlgen
47func (c Comment) IsAuthored() {}