Skip to content

Commit 64c5ebe

Browse files
committed
Hide Snapshot::Timeline from public access
1 parent afed1de commit 64c5ebe

11 files changed

Lines changed: 33 additions & 28 deletions

api/graphql/models/lazy_bug.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (lb *lazyBug) Timeline() ([]bug.TimelineItem, error) {
141141
if err != nil {
142142
return nil, err
143143
}
144-
return lb.snap.Timeline, nil
144+
return lb.snap.Timeline(), nil
145145
}
146146

147147
func (lb *lazyBug) Operations() ([]bug.Operation, error) {
@@ -207,7 +207,7 @@ func (l *loadedBug) CreatedAt() time.Time {
207207
}
208208

209209
func (l *loadedBug) Timeline() ([]bug.TimelineItem, error) {
210-
return l.Snapshot.Timeline, nil
210+
return l.Snapshot.Timeline(), nil
211211
}
212212

213213
func (l *loadedBug) Operations() ([]bug.Operation, error) {

bug/op_add_comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (op *AddCommentOperation) Apply(snapshot *Snapshot) {
4545
CommentTimelineItem: NewCommentTimelineItem(comment),
4646
}
4747

48-
snapshot.Timeline = append(snapshot.Timeline, item)
48+
snapshot.timeline = append(snapshot.timeline, item)
4949
}
5050

5151
func (op *AddCommentOperation) GetFiles() []repository.Hash {

bug/op_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (op *CreateOperation) Apply(snapshot *Snapshot) {
6464
snapshot.author = op.Author_
6565
snapshot.CreateTime = op.Time()
6666

67-
snapshot.Timeline = []TimelineItem{
67+
snapshot.timeline = []TimelineItem{
6868
&CreateTimelineItem{
6969
CommentTimelineItem: NewCommentTimelineItem(comment),
7070
},

bug/op_create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestCreate(t *testing.T) {
4747
participants: []identity.Interface{rene},
4848
actors: []identity.Interface{rene},
4949
CreateTime: create.Time(),
50-
Timeline: []TimelineItem{
50+
timeline: []TimelineItem{
5151
&CreateTimelineItem{
5252
CommentTimelineItem: NewCommentTimelineItem(comment),
5353
},

bug/op_edit_comment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
3838
commentId := entity.CombineIds(snapshot.Id(), op.Target)
3939

4040
var target TimelineItem
41-
for i, item := range snapshot.Timeline {
41+
for i, item := range snapshot.timeline {
4242
if item.Id() == commentId {
43-
target = snapshot.Timeline[i]
43+
target = snapshot.timeline[i]
4444
break
4545
}
4646
}

bug/op_edit_comment_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,32 @@ func TestEdit(t *testing.T) {
4343
edit := NewEditCommentOp(rene, unix, create.Id(), "create edited", nil)
4444
edit.Apply(&snapshot)
4545

46-
require.Len(t, snapshot.Timeline, 4)
47-
require.Len(t, snapshot.Timeline[0].(*CreateTimelineItem).History, 2)
48-
require.Len(t, snapshot.Timeline[1].(*AddCommentTimelineItem).History, 1)
49-
require.Len(t, snapshot.Timeline[3].(*AddCommentTimelineItem).History, 1)
46+
require.Len(t, snapshot.Timeline(), 4)
47+
require.Len(t, snapshot.Timeline()[0].(*CreateTimelineItem).History, 2)
48+
require.Len(t, snapshot.Timeline()[1].(*AddCommentTimelineItem).History, 1)
49+
require.Len(t, snapshot.Timeline()[3].(*AddCommentTimelineItem).History, 1)
5050
require.Equal(t, snapshot.Comments()[0].Message, "create edited")
5151
require.Equal(t, snapshot.Comments()[1].Message, "comment 1")
5252
require.Equal(t, snapshot.Comments()[2].Message, "comment 2")
5353

5454
edit2 := NewEditCommentOp(rene, unix, comment1.Id(), "comment 1 edited", nil)
5555
edit2.Apply(&snapshot)
5656

57-
require.Len(t, snapshot.Timeline, 4)
58-
require.Len(t, snapshot.Timeline[0].(*CreateTimelineItem).History, 2)
59-
require.Len(t, snapshot.Timeline[1].(*AddCommentTimelineItem).History, 2)
60-
require.Len(t, snapshot.Timeline[3].(*AddCommentTimelineItem).History, 1)
57+
require.Len(t, snapshot.Timeline(), 4)
58+
require.Len(t, snapshot.Timeline()[0].(*CreateTimelineItem).History, 2)
59+
require.Len(t, snapshot.Timeline()[1].(*AddCommentTimelineItem).History, 2)
60+
require.Len(t, snapshot.Timeline()[3].(*AddCommentTimelineItem).History, 1)
6161
require.Equal(t, snapshot.Comments()[0].Message, "create edited")
6262
require.Equal(t, snapshot.Comments()[1].Message, "comment 1 edited")
6363
require.Equal(t, snapshot.Comments()[2].Message, "comment 2")
6464

6565
edit3 := NewEditCommentOp(rene, unix, comment2.Id(), "comment 2 edited", nil)
6666
edit3.Apply(&snapshot)
6767

68-
require.Len(t, snapshot.Timeline, 4)
69-
require.Len(t, snapshot.Timeline[0].(*CreateTimelineItem).History, 2)
70-
require.Len(t, snapshot.Timeline[1].(*AddCommentTimelineItem).History, 2)
71-
require.Len(t, snapshot.Timeline[3].(*AddCommentTimelineItem).History, 2)
68+
require.Len(t, snapshot.Timeline(), 4)
69+
require.Len(t, snapshot.Timeline()[0].(*CreateTimelineItem).History, 2)
70+
require.Len(t, snapshot.Timeline()[1].(*AddCommentTimelineItem).History, 2)
71+
require.Len(t, snapshot.Timeline()[3].(*AddCommentTimelineItem).History, 2)
7272
require.Equal(t, snapshot.Comments()[0].Message, "create edited")
7373
require.Equal(t, snapshot.Comments()[1].Message, "comment 1 edited")
7474
require.Equal(t, snapshot.Comments()[2].Message, "comment 2 edited")

bug/op_label_change.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ AddLoop:
6767
Removed: op.Removed,
6868
}
6969

70-
snapshot.Timeline = append(snapshot.Timeline, item)
70+
snapshot.timeline = append(snapshot.timeline, item)
7171
}
7272

7373
func (op *LabelChangeOperation) Validate() error {

bug/op_set_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (op *SetStatusOperation) Apply(snapshot *Snapshot) {
3333
Status: op.Status,
3434
}
3535

36-
snapshot.Timeline = append(snapshot.Timeline, item)
36+
snapshot.timeline = append(snapshot.timeline, item)
3737
}
3838

3939
func (op *SetStatusOperation) Validate() error {

bug/op_set_title.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (op *SetTitleOperation) Apply(snapshot *Snapshot) {
3636
Was: op.Was,
3737
}
3838

39-
snapshot.Timeline = append(snapshot.Timeline, item)
39+
snapshot.timeline = append(snapshot.timeline, item)
4040
}
4141

4242
func (op *SetTitleOperation) Validate() error {

bug/snapshot.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Snapshot struct {
2121
participants []identity.Interface
2222
CreateTime time.Time
2323

24-
Timeline []TimelineItem
24+
timeline []TimelineItem
2525

2626
Operations []Operation
2727
}
@@ -70,6 +70,11 @@ func (snap *Snapshot) Participants() []identity.Interface {
7070
return snap.participants
7171
}
7272

73+
// Return the bugs timeline
74+
func (snap *Snapshot) Timeline() []TimelineItem {
75+
return snap.timeline
76+
}
77+
7378
// Return the last time a bug was modified
7479
func (snap *Snapshot) EditTime() time.Time {
7580
if len(snap.Operations) == 0 {
@@ -86,9 +91,9 @@ func (snap *Snapshot) GetCreateMetadata(key string) (string, bool) {
8691

8792
// SearchTimelineItem will search in the timeline for an item matching the given hash
8893
func (snap *Snapshot) SearchTimelineItem(id entity.Id) (TimelineItem, error) {
89-
for i := range snap.Timeline {
90-
if snap.Timeline[i].Id() == id {
91-
return snap.Timeline[i], nil
94+
for i := range snap.timeline {
95+
if snap.timeline[i].Id() == id {
96+
return snap.timeline[i], nil
9297
}
9398
}
9499

0 commit comments

Comments
 (0)