1package bug
2
3import (
4 "fmt"
5 "time"
6
7 "github.com/MichaelMure/git-bug/util/git"
8)
9
10// Snapshot is a compiled form of the Bug data structure used for storage and merge
11type Snapshot struct {
12 id string
13
14 Status Status
15 Title string
16 Comments []Comment
17 Labels []Label
18 Author Person
19 CreatedAt time.Time
20
21 Timeline []TimelineItem
22
23 Operations []Operation
24}
25
26// Return the Bug identifier
27func (snap *Snapshot) Id() string {
28 return snap.id
29}
30
31// Return the Bug identifier truncated for human consumption
32func (snap *Snapshot) HumanId() string {
33 return fmt.Sprintf("%.8s", snap.id)
34}
35
36// Deprecated:should be moved in UI code
37func (snap *Snapshot) Summary() string {
38 return fmt.Sprintf("C:%d L:%d",
39 len(snap.Comments)-1,
40 len(snap.Labels),
41 )
42}
43
44// Return the last time a bug was modified
45func (snap *Snapshot) LastEditTime() time.Time {
46 if len(snap.Operations) == 0 {
47 return time.Unix(0, 0)
48 }
49
50 return snap.Operations[len(snap.Operations)-1].Time()
51}
52
53// Return the last timestamp a bug was modified
54func (snap *Snapshot) LastEditUnix() int64 {
55 if len(snap.Operations) == 0 {
56 return 0
57 }
58
59 return snap.Operations[len(snap.Operations)-1].GetUnixTime()
60}
61
62// SearchTimelineItem will search in the timeline for an item matching the given hash
63func (snap *Snapshot) SearchTimelineItem(hash git.Hash) (TimelineItem, error) {
64 for i := range snap.Timeline {
65 if snap.Timeline[i].Hash() == hash {
66 return snap.Timeline[i], nil
67 }
68 }
69
70 return nil, fmt.Errorf("timeline item not found")
71}