snapshot.go

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