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