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