Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
31d915c
Hide Snapshot::Title field from public access
GlancingMind Jun 28, 2021
0ad4f36
Hide Snapshot::Status from public access
GlancingMind Jun 28, 2021
3a770aa
Hide Snapshot::Comments from public access
GlancingMind Jul 3, 2021
4b03767
Hide Snapshot::Labels from public access
GlancingMind Jul 5, 2021
188681e
Hide Snapshot::Author from public access
GlancingMind Jul 5, 2021
13da2ab
Hide Snapshot::Actors from public access
GlancingMind Jul 5, 2021
afed1de
Hide Snapshot::Participants from public access
GlancingMind Jul 5, 2021
64c5ebe
Hide Snapshot::Timeline from public access
GlancingMind Jul 5, 2021
5275415
Remove TODO proposal
GlancingMind Jul 15, 2021
d404a76
Move AddLabel loop into separate function
GlancingMind Jul 15, 2021
2176968
Move RemoveLabel loop into separate function
GlancingMind Jul 15, 2021
e175475
Add Snapshot::HasLabel methode
GlancingMind Jul 15, 2021
cb7012b
Do not sort labels in ChangeLabelOperation
GlancingMind Jul 15, 2021
9020cdd
Use element instead of index in loops
GlancingMind Jul 16, 2021
0d8c3f9
Add Snapshot::appendTimelineItem methode
GlancingMind Jul 16, 2021
66989cf
Hide Comment::Message from public access
GlancingMind Jul 20, 2021
4fdc3c7
Remove message to prevent following error:
GlancingMind Jul 21, 2021
3b6bdde
Use dedicated mutation functions for comment props
GlancingMind Jul 22, 2021
3781204
Hide Comment::Files from public access
GlancingMind Jul 22, 2021
2d20d6f
Hide Comment::UnixTime from public access
GlancingMind Jul 22, 2021
d2c043e
Move Timestamp formatting functions into timestamp
GlancingMind Jul 22, 2021
2e8c47e
Add Snapshot::UpdateComment
GlancingMind Jul 22, 2021
2a23fab
Prevent creation of invalid comments
GlancingMind Jul 24, 2021
9dae188
Implement Comment::Edit
GlancingMind Jul 26, 2021
d6b0de5
Implement Comment:Edited()
GlancingMind Jul 27, 2021
b8ee0a8
Implement Comment:MessageIsEmpty()
GlancingMind Jul 27, 2021
683e4d1
Removed remains of CommentTimelineItem
GlancingMind Jul 27, 2021
8c74135
Rename Alteration to CommentHistoryStep
GlancingMind Jul 31, 2021
6800587
Access comment properites via methodes...
GlancingMind Jul 31, 2021
28082f5
Fix unit test compilation error
GlancingMind Jul 31, 2021
9d482fe
Make comment history public to prevent this error:
GlancingMind Jul 31, 2021
b10f132
Set Comment::LastEdited within Comment::Edit()
GlancingMind Jul 31, 2021
9630ee8
Update comment only after storing current state
GlancingMind Jul 31, 2021
91c3f9f
Rename AddCommentTimelineItem to CommentTimelineItem
GlancingMind Jul 31, 2021
720a6bf
Fix: Update GraphQL to CommentTimelineItem rename
GlancingMind Jul 31, 2021
c082e83
Make Commet::History private
GlancingMind Jul 31, 2021
b0e7bc4
Fix graphql_test fail of following commit:
GlancingMind Jul 31, 2021
1b98da9
Reintroduce failing test
GlancingMind Aug 1, 2021
e1435fb
Let CommentTimelineItem only hold the comments id
GlancingMind Aug 1, 2021
1303efe
Add IsAuthored to TimelineItem interface
GlancingMind Aug 2, 2021
b189ae5
Remove pointer reciever from comment methodes
GlancingMind Aug 2, 2021
6201e64
GraphQL: Implement CommentTimelineItems resolve
GlancingMind Aug 2, 2021
7f5392d
Fix OpCreateTest and OpEditCommentTest
GlancingMind Aug 2, 2021
c2e4a4f
Remove CreateTimelineItem
GlancingMind Aug 3, 2021
0016839
Fix eslint
GlancingMind Aug 3, 2021
2fef4c2
Fix eslint
GlancingMind Aug 3, 2021
6f21fb4
Remove obsolete check
GlancingMind Aug 3, 2021
be58736
Fix termui comment selection
GlancingMind Aug 3, 2021
29c9543
Fix nil pointer error for WebUI
GlancingMind Aug 3, 2021
8af3738
Add Bug::Description to graphql schema
GlancingMind Aug 4, 2021
3b8b6db
WebUI: Add description for bug fragment
GlancingMind Aug 4, 2021
c66f7fe
GraphQL: Add remaining fields to Comment type
GlancingMind Aug 4, 2021
510a54c
Resolve Comment and CommentTimelineItem as Comment
GlancingMind Aug 5, 2021
9dfba36
WebUI: Fix display of description
GlancingMind Aug 5, 2021
3fb1037
WebUI: Fix comment counter
GlancingMind Aug 5, 2021
690cf20
Rename timestamp: LastEdit to LastEdited
GlancingMind Aug 5, 2021
31c5f2f
Rename Comment:MessageIsEmpty to HasEmptyMessage
GlancingMind Aug 5, 2021
6bfb32c
Rename CommentHistoryStep to Alteration
GlancingMind Aug 5, 2021
1e02465
Move Comment into separate package
GlancingMind Aug 6, 2021
a740229
Add documentation, to regenerate connection files
GlancingMind Aug 7, 2021
eae0e37
Let snapshot only hold identity IDs
GlancingMind Aug 11, 2021
cf57a15
Backup comment patch
GlancingMind Aug 11, 2021
3814def
Fix: commands/show printing of participants
GlancingMind Aug 12, 2021
a2d0a14
Fix: commands/show printing of description
GlancingMind Aug 12, 2021
3eca82a
Fix commands/ls comment counter: off-by-one error
GlancingMind Aug 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions api/graphql/models/lazy_bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (lb *lazyBug) Comments() ([]bug.Comment, error) {
if err != nil {
return nil, err
}
return lb.snap.Comments, nil
return lb.snap.Comments(), nil
}

func (lb *lazyBug) Labels() []bug.Label {
Expand Down Expand Up @@ -141,7 +141,7 @@ func (lb *lazyBug) Timeline() ([]bug.TimelineItem, error) {
if err != nil {
return nil, err
}
return lb.snap.Timeline, nil
return lb.snap.Timeline(), nil
}

func (lb *lazyBug) Operations() ([]bug.Operation, error) {
Expand All @@ -167,36 +167,36 @@ func (l *loadedBug) LastEdit() time.Time {
}

func (l *loadedBug) Status() bug.Status {
return l.Snapshot.Status
return l.Snapshot.Status()
}

func (l *loadedBug) Title() string {
return l.Snapshot.Title
return l.Snapshot.Title()
}

func (l *loadedBug) Comments() ([]bug.Comment, error) {
return l.Snapshot.Comments, nil
return l.Snapshot.Comments(), nil
}

func (l *loadedBug) Labels() []bug.Label {
return l.Snapshot.Labels
return l.Snapshot.Labels()
}

func (l *loadedBug) Author() (IdentityWrapper, error) {
return NewLoadedIdentity(l.Snapshot.Author), nil
return NewLoadedIdentity(l.Snapshot.Author()), nil
}

func (l *loadedBug) Actors() ([]IdentityWrapper, error) {
res := make([]IdentityWrapper, len(l.Snapshot.Actors))
for i, actor := range l.Snapshot.Actors {
res := make([]IdentityWrapper, len(l.Snapshot.Actors()))
for i, actor := range l.Snapshot.Actors() {
res[i] = NewLoadedIdentity(actor)
}
return res, nil
}

func (l *loadedBug) Participants() ([]IdentityWrapper, error) {
res := make([]IdentityWrapper, len(l.Snapshot.Participants))
for i, participant := range l.Snapshot.Participants {
res := make([]IdentityWrapper, len(l.Snapshot.Participants()))
for i, participant := range l.Snapshot.Participants() {
res[i] = NewLoadedIdentity(participant)
}
return res, nil
Expand All @@ -207,7 +207,7 @@ func (l *loadedBug) CreatedAt() time.Time {
}

func (l *loadedBug) Timeline() ([]bug.TimelineItem, error) {
return l.Snapshot.Timeline, nil
return l.Snapshot.Timeline(), nil
}

func (l *loadedBug) Operations() ([]bug.Operation, error) {
Expand Down
2 changes: 1 addition & 1 deletion bridge/github/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (ge *githubExporter) exportBug(ctx context.Context, b *cache.BugCache, out

// first operation is always createOp
createOp := snapshot.Operations[0].(*bug.CreateOperation)
author := snapshot.Author
author := snapshot.Author()

// skip bug if origin is not allowed
origin, ok := snapshot.GetCreateMetadata(core.MetaKeyOrigin)
Expand Down
2 changes: 1 addition & 1 deletion bridge/gitlab/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, out

// first operation is always createOp
createOp := snapshot.Operations[0].(*bug.CreateOperation)
author := snapshot.Author
author := snapshot.Author()

// get gitlab bug ID
gitlabID, ok := snapshot.GetCreateMetadata(metaKeyGitlabId)
Expand Down
2 changes: 1 addition & 1 deletion bridge/gitlab/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n
case NOTE_DESCRIPTION_CHANGED:
issue := gi.iterator.IssueValue()

firstComment := b.Snapshot().Comments[0]
firstComment := b.Snapshot().Comments()[0]
// since gitlab doesn't provide the issue history
// we should check for "changed the description" notes and compare issue texts
// TODO: Check only one time and ignore next 'description change' within one issue
Expand Down
2 changes: 1 addition & 1 deletion bridge/jira/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (je *jiraExporter) exportBug(ctx context.Context, b *cache.BugCache, out ch

// first operation is always createOp
createOp := snapshot.Operations[0].(*bug.CreateOperation)
author := snapshot.Author
author := snapshot.Author()

// skip bug if it was imported from some other bug system
origin, ok := snapshot.GetCreateMetadata(core.MetaKeyOrigin)
Expand Down
2 changes: 1 addition & 1 deletion bug/bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (bug *Bug) Operations() []Operation {
func (bug *Bug) Compile() Snapshot {
snap := Snapshot{
id: bug.Id(),
Status: OpenStatus,
status: OpenStatus,
}

for _, op := range bug.Operations() {
Expand Down
4 changes: 2 additions & 2 deletions bug/op_add_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func (op *AddCommentOperation) Apply(snapshot *Snapshot) {
UnixTime: timestamp.Timestamp(op.UnixTime),
}

snapshot.Comments = append(snapshot.Comments, comment)
snapshot.appendComment(comment)

item := &AddCommentTimelineItem{
CommentTimelineItem: NewCommentTimelineItem(comment),
}

snapshot.Timeline = append(snapshot.Timeline, item)
snapshot.timeline = append(snapshot.timeline, item)
Copy link
Owner Author

@GlancingMind GlancingMind Jul 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide a Snapshot::appendTimelineItem method, similar to Snapshot::appendComment.

Considerations:
1. Operations can still access snapshot::comments, TimelineItems, etc. as they are in the same package. What exactly does implementing this dedicated append-methods improve?
2. Maybe put Comments, TimeLine, etc. in their own packages. This packages provide methods to also handle a collection of Comments, TimeLineItems, etc. Then a Snapshot won't have the implementation detail of a Comment collection and their is only way to append to the comment collection. Either through Snapshot.Comments.append() or via Snapshot:appendComment(), which itself will call Comments.append().

Update: This might be no longer required. Snapshot could append the TimelineItems (aka. Events) itself to the timeline. E.g. SetTitle will post a the SetTitleTimelineItem itself to the Timeline. Further reducing the Operations logic.

}

func (op *AddCommentOperation) GetFiles() []repository.Hash {
Expand Down
10 changes: 4 additions & 6 deletions bug/op_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ func (op *CreateOperation) Apply(snapshot *Snapshot) {
}

snapshot.id = op.Id()

snapshot.addActor(op.Author_)
snapshot.addParticipant(op.Author_)

snapshot.Title = op.Title
snapshot.changeTitleTo(op.Title)

comment := Comment{
id: entity.CombineIds(snapshot.Id(), op.Id()),
Expand All @@ -62,11 +60,11 @@ func (op *CreateOperation) Apply(snapshot *Snapshot) {
UnixTime: timestamp.Timestamp(op.UnixTime),
}

snapshot.Comments = []Comment{comment}
snapshot.Author = op.Author_
snapshot.appendComment(comment)
snapshot.author = op.Author_
snapshot.CreateTime = op.Time()

snapshot.Timeline = []TimelineItem{
snapshot.timeline = []TimelineItem{
&CreateTimelineItem{
CommentTimelineItem: NewCommentTimelineItem(comment),
},
Expand Down
12 changes: 6 additions & 6 deletions bug/op_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func TestCreate(t *testing.T) {

expected := Snapshot{
id: create.Id(),
Title: "title",
Comments: []Comment{
title: "title",
comments: []Comment{
comment,
},
Author: rene,
Participants: []identity.Interface{rene},
Actors: []identity.Interface{rene},
author: rene,
participants: []identity.Interface{rene},
actors: []identity.Interface{rene},
CreateTime: create.Time(),
Timeline: []TimelineItem{
timeline: []TimelineItem{
&CreateTimelineItem{
CommentTimelineItem: NewCommentTimelineItem(comment),
},
Expand Down
14 changes: 8 additions & 6 deletions bug/op_edit_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
commentId := entity.CombineIds(snapshot.Id(), op.Target)

var target TimelineItem
for i, item := range snapshot.Timeline {
for i, item := range snapshot.timeline {
if item.Id() == commentId {
target = snapshot.Timeline[i]
target = snapshot.timeline[i]
break
}
}
Expand Down Expand Up @@ -72,10 +72,12 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {

// Updating the corresponding comment

for i := range snapshot.Comments {
if snapshot.Comments[i].Id() == commentId {
snapshot.Comments[i].Message = op.Message
snapshot.Comments[i].Files = op.Files
//TODO use snapshot.SearchComment instead of iteration
//TODO put *editComment* in snapshot or add *edit* to Comment interface?
for i := range snapshot.Comments() {
if snapshot.Comments()[i].Id() == commentId {
snapshot.Comments()[i].Message = op.Message
snapshot.Comments()[i].Files = op.Files
break
}
}
Expand Down
42 changes: 21 additions & 21 deletions bug/op_edit_comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,35 @@ func TestEdit(t *testing.T) {
edit := NewEditCommentOp(rene, unix, create.Id(), "create edited", nil)
edit.Apply(&snapshot)

require.Len(t, snapshot.Timeline, 4)
require.Len(t, snapshot.Timeline[0].(*CreateTimelineItem).History, 2)
require.Len(t, snapshot.Timeline[1].(*AddCommentTimelineItem).History, 1)
require.Len(t, snapshot.Timeline[3].(*AddCommentTimelineItem).History, 1)
require.Equal(t, snapshot.Comments[0].Message, "create edited")
require.Equal(t, snapshot.Comments[1].Message, "comment 1")
require.Equal(t, snapshot.Comments[2].Message, "comment 2")
require.Len(t, snapshot.Timeline(), 4)
require.Len(t, snapshot.Timeline()[0].(*CreateTimelineItem).History, 2)
require.Len(t, snapshot.Timeline()[1].(*AddCommentTimelineItem).History, 1)
require.Len(t, snapshot.Timeline()[3].(*AddCommentTimelineItem).History, 1)
require.Equal(t, snapshot.Comments()[0].Message, "create edited")
require.Equal(t, snapshot.Comments()[1].Message, "comment 1")
require.Equal(t, snapshot.Comments()[2].Message, "comment 2")

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

require.Len(t, snapshot.Timeline, 4)
require.Len(t, snapshot.Timeline[0].(*CreateTimelineItem).History, 2)
require.Len(t, snapshot.Timeline[1].(*AddCommentTimelineItem).History, 2)
require.Len(t, snapshot.Timeline[3].(*AddCommentTimelineItem).History, 1)
require.Equal(t, snapshot.Comments[0].Message, "create edited")
require.Equal(t, snapshot.Comments[1].Message, "comment 1 edited")
require.Equal(t, snapshot.Comments[2].Message, "comment 2")
require.Len(t, snapshot.Timeline(), 4)
require.Len(t, snapshot.Timeline()[0].(*CreateTimelineItem).History, 2)
require.Len(t, snapshot.Timeline()[1].(*AddCommentTimelineItem).History, 2)
require.Len(t, snapshot.Timeline()[3].(*AddCommentTimelineItem).History, 1)
require.Equal(t, snapshot.Comments()[0].Message, "create edited")
require.Equal(t, snapshot.Comments()[1].Message, "comment 1 edited")
require.Equal(t, snapshot.Comments()[2].Message, "comment 2")

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

require.Len(t, snapshot.Timeline, 4)
require.Len(t, snapshot.Timeline[0].(*CreateTimelineItem).History, 2)
require.Len(t, snapshot.Timeline[1].(*AddCommentTimelineItem).History, 2)
require.Len(t, snapshot.Timeline[3].(*AddCommentTimelineItem).History, 2)
require.Equal(t, snapshot.Comments[0].Message, "create edited")
require.Equal(t, snapshot.Comments[1].Message, "comment 1 edited")
require.Equal(t, snapshot.Comments[2].Message, "comment 2 edited")
require.Len(t, snapshot.Timeline(), 4)
require.Len(t, snapshot.Timeline()[0].(*CreateTimelineItem).History, 2)
require.Len(t, snapshot.Timeline()[1].(*AddCommentTimelineItem).History, 2)
require.Len(t, snapshot.Timeline()[3].(*AddCommentTimelineItem).History, 2)
require.Equal(t, snapshot.Comments()[0].Message, "create edited")
require.Equal(t, snapshot.Comments()[1].Message, "comment 1 edited")
require.Equal(t, snapshot.Comments()[2].Message, "comment 2 edited")
}

func TestEditCommentSerialize(t *testing.T) {
Expand Down
22 changes: 12 additions & 10 deletions bug/op_label_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,32 @@ func (op *LabelChangeOperation) Apply(snapshot *Snapshot) {

// Add in the set
AddLoop:
//TODO extract this in a separate methode
for _, added := range op.Added {
for _, label := range snapshot.Labels {
for _, label := range snapshot.labels {
if label == added {
// Already exist
continue AddLoop
}
}

snapshot.Labels = append(snapshot.Labels, added)
snapshot.labels = append(snapshot.labels, added)
}

// Remove in the set
//TODO extract this in a separate methode
for _, removed := range op.Removed {
for i, label := range snapshot.Labels {
for i, label := range snapshot.labels {
if label == removed {
snapshot.Labels[i] = snapshot.Labels[len(snapshot.Labels)-1]
snapshot.Labels = snapshot.Labels[:len(snapshot.Labels)-1]
snapshot.labels[i] = snapshot.labels[len(snapshot.labels)-1]
snapshot.labels = snapshot.labels[:len(snapshot.labels)-1]
}
}
}

// Sort
sort.Slice(snapshot.Labels, func(i, j int) bool {
return string(snapshot.Labels[i]) < string(snapshot.Labels[j])
sort.Slice(snapshot.labels, func(i, j int) bool {
return string(snapshot.labels[i]) < string(snapshot.labels[j])
})

item := &LabelChangeTimelineItem{
Expand All @@ -65,7 +67,7 @@ AddLoop:
Removed: op.Removed,
}

snapshot.Timeline = append(snapshot.Timeline, item)
snapshot.timeline = append(snapshot.timeline, item)
}

func (op *LabelChangeOperation) Validate() error {
Expand Down Expand Up @@ -164,7 +166,7 @@ func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, r
}

// check that the label doesn't already exist
if labelExist(snap.Labels, label) {
if labelExist(snap.labels, label) {
results = append(results, LabelChangeResult{Label: label, Status: LabelChangeAlreadySet})
continue
}
Expand All @@ -183,7 +185,7 @@ func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, r
}

// check that the label actually exist
if !labelExist(snap.Labels, label) {
if !labelExist(snap.labels, label) {
results = append(results, LabelChangeResult{Label: label, Status: LabelChangeDoesntExist})
continue
}
Expand Down
4 changes: 2 additions & 2 deletions bug/op_set_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (op *SetStatusOperation) Id() entity.Id {
}

func (op *SetStatusOperation) Apply(snapshot *Snapshot) {
snapshot.Status = op.Status
snapshot.setStatusTo(op.Status)
snapshot.addActor(op.Author_)

item := &SetStatusTimelineItem{
Expand All @@ -33,7 +33,7 @@ func (op *SetStatusOperation) Apply(snapshot *Snapshot) {
Status: op.Status,
}

snapshot.Timeline = append(snapshot.Timeline, item)
snapshot.timeline = append(snapshot.timeline, item)
}

func (op *SetStatusOperation) Validate() error {
Expand Down
4 changes: 2 additions & 2 deletions bug/op_set_title.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (op *SetTitleOperation) Id() entity.Id {
}

func (op *SetTitleOperation) Apply(snapshot *Snapshot) {
snapshot.Title = op.Title
snapshot.changeTitleTo(op.Title)
snapshot.addActor(op.Author_)

item := &SetTitleTimelineItem{
Expand All @@ -36,7 +36,7 @@ func (op *SetTitleOperation) Apply(snapshot *Snapshot) {
Was: op.Was,
}

snapshot.Timeline = append(snapshot.Timeline, item)
snapshot.timeline = append(snapshot.timeline, item)
}

func (op *SetTitleOperation) Validate() error {
Expand Down
Loading