snapshot.go

 1package bug
 2
 3import (
 4	"fmt"
 5	"github.com/dustin/go-humanize"
 6	"time"
 7)
 8
 9// Snapshot is a compiled form of the Bug data structure used for storage and merge
10type Snapshot struct {
11	id string
12
13	Status   Status    `json:"status"`
14	Title    string    `json:"title"`
15	Comments []Comment `json:"comments"`
16	Labels   []Label   `json:"labels"`
17
18	Operations []Operation
19}
20
21// Return the Bug identifier
22func (snap Snapshot) Id() string {
23	return snap.id
24}
25
26// Return the Bug identifier truncated for human consumption
27func (snap Snapshot) HumanId() string {
28	return fmt.Sprintf("%.8s", snap.id)
29}
30
31func (snap Snapshot) Summary() string {
32	return fmt.Sprintf("C:%d L:%d   %s",
33		len(snap.Comments)-1,
34		len(snap.Labels),
35		humanize.Time(snap.LastEdit()),
36	)
37}
38
39// Return the last time a bug was modified
40func (snap Snapshot) LastEdit() time.Time {
41	if len(snap.Operations) == 0 {
42		return time.Unix(0, 0)
43	}
44
45	return snap.Operations[len(snap.Operations)-1].Time()
46}