1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
package bug
import (
"fmt"
"time"
"github.com/git-bug/git-bug/entities/common"
"github.com/git-bug/git-bug/entities/identity"
"github.com/git-bug/git-bug/entity"
"github.com/git-bug/git-bug/entity/dag"
)
var _ dag.Snapshot = &Snapshot{}
// Snapshot is a compiled form of the Bug data structure used for storage and merge
type Snapshot struct {
id entity.Id
Status common.Status
Title string
Comments []Comment
Labels []common.Label
Author identity.Interface
Actors []identity.Interface
Participants []identity.Interface
CreateTime time.Time
Timeline []TimelineItem
Operations []dag.Operation
}
// Id returns the Bug identifier
func (snap *Snapshot) Id() entity.Id {
if snap.id == "" {
// simply panic as it would be a coding error (no id provided at construction)
panic("no id")
}
return snap.id
}
func (snap *Snapshot) AllOperations() []dag.Operation {
return snap.Operations
}
func (snap *Snapshot) AppendOperation(op dag.Operation) {
snap.Operations = append(snap.Operations, op)
}
// EditTime returns the last time a bug was modified
func (snap *Snapshot) EditTime() time.Time {
if len(snap.Operations) == 0 {
return time.Unix(0, 0)
}
return snap.Operations[len(snap.Operations)-1].Time()
}
// GetCreateMetadata return the creation metadata
func (snap *Snapshot) GetCreateMetadata(key string) (string, bool) {
return snap.Operations[0].GetMetadata(key)
}
// SearchTimelineItem will search in the timeline for an item matching the given hash
func (snap *Snapshot) SearchTimelineItem(id entity.CombinedId) (TimelineItem, error) {
for i := range snap.Timeline {
if snap.Timeline[i].CombinedId() == id {
return snap.Timeline[i], nil
}
}
return nil, fmt.Errorf("timeline item not found")
}
// SearchComment will search for a comment matching the given id
func (snap *Snapshot) SearchComment(id entity.CombinedId) (*Comment, error) {
for _, c := range snap.Comments {
if c.combinedId == id {
return &c, nil
}
}
return nil, fmt.Errorf("comment not found")
}
// SearchCommentByOpId will search for a comment generated by the given operation Id
func (snap *Snapshot) SearchCommentByOpId(id entity.Id) (*Comment, error) {
for _, c := range snap.Comments {
if c.targetId == id {
return &c, nil
}
}
return nil, fmt.Errorf("comment not found")
}
// append the operation author to the actors list
func (snap *Snapshot) addActor(actor identity.Interface) {
for _, a := range snap.Actors {
if actor.Id() == a.Id() {
return
}
}
snap.Actors = append(snap.Actors, actor)
}
// append the operation author to the participants list
func (snap *Snapshot) addParticipant(participant identity.Interface) {
for _, p := range snap.Participants {
if participant.Id() == p.Id() {
return
}
}
snap.Participants = append(snap.Participants, participant)
}
// HasParticipant return true if the id is a participant
func (snap *Snapshot) HasParticipant(id entity.Id) bool {
for _, p := range snap.Participants {
if p.Id() == id {
return true
}
}
return false
}
// HasAnyParticipant return true if one of the ids is a participant
func (snap *Snapshot) HasAnyParticipant(ids ...entity.Id) bool {
for _, id := range ids {
if snap.HasParticipant(id) {
return true
}
}
return false
}
// HasActor return true if the id is a actor
func (snap *Snapshot) HasActor(id entity.Id) bool {
for _, p := range snap.Actors {
if p.Id() == id {
return true
}
}
return false
}
// HasAnyActor return true if one of the ids is a actor
func (snap *Snapshot) HasAnyActor(ids ...entity.Id) bool {
for _, id := range ids {
if snap.HasActor(id) {
return true
}
}
return false
}
// IsAuthored is a sign post method for gqlgen
func (snap *Snapshot) IsAuthored() {}
|