snapshot.go

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