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 Actors []identity.Interface
21 Participants []identity.Interface
22 CreatedAt time.Time
23
24 Timeline []TimelineItem
25
26 Operations []Operation
27}
28
29// Return the Bug identifier
30func (snap *Snapshot) Id() string {
31 return snap.id
32}
33
34// Return the Bug identifier truncated for human consumption
35func (snap *Snapshot) HumanId() string {
36 return FormatHumanID(snap.id)
37}
38
39// Return the last time a bug was modified
40func (snap *Snapshot) LastEditTime() 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}
47
48// Return the last timestamp a bug was modified
49func (snap *Snapshot) LastEditUnix() int64 {
50 if len(snap.Operations) == 0 {
51 return 0
52 }
53
54 return snap.Operations[len(snap.Operations)-1].GetUnixTime()
55}
56
57// SearchTimelineItem will search in the timeline for an item matching the given hash
58func (snap *Snapshot) SearchTimelineItem(hash git.Hash) (TimelineItem, error) {
59 for i := range snap.Timeline {
60 if snap.Timeline[i].Hash() == hash {
61 return snap.Timeline[i], nil
62 }
63 }
64
65 return nil, fmt.Errorf("timeline item not found")
66}
67
68// append the operation author to the actors list
69func (snap *Snapshot) addActor(actor identity.Interface) {
70 for _, a := range snap.Actors {
71 if actor.Id() == a.Id() {
72 return
73 }
74 }
75
76 snap.Actors = append(snap.Actors, actor)
77}
78
79// append the operation author to the participants list
80func (snap *Snapshot) addParticipant(participant identity.Interface) {
81 for _, p := range snap.Participants {
82 if participant.Id() == p.Id() {
83 return
84 }
85 }
86
87 snap.Participants = append(snap.Participants, participant)
88}
89
90// Sign post method for gqlgen
91func (snap *Snapshot) IsAuthored() {}