-
Notifications
You must be signed in to change notification settings - Fork 86
Do not generate event log for reorder event #2196
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2196 +/- ##
=========================================
Coverage ? 69.38%
=========================================
Files ? 173
Lines ? 16393
Branches ? 0
=========================================
Hits ? 11375
Misses ? 3924
Partials ? 1094
Continue to review full report at Codecov.
|
workitem/workitem_repository.go
Outdated
@@ -545,6 +545,21 @@ func (r *GormWorkItemRepository) Reorder(ctx context.Context, spaceID uuid.UUID, | |||
continue | |||
} | |||
fieldValue := wi.Fields[fieldName] | |||
// Remove Assignee/Labels/Boardcolumns (fields with kind list) if they do not have a value | |||
if fieldDef.Type.GetKind() == "list" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot use fieldDef.Type.GetKind() == workitem.KindList
because it would cause a cyclic dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you can use fieldDef.Type.GetKind() == KindList
. I mean you're already in the workitem
package. So no need to import it again ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See ee41af2
I should've seen that earlier :)
workitem/workitem_repository.go
Outdated
@@ -587,7 +602,8 @@ func (r *GormWorkItemRepository) Save(ctx context.Context, spaceID uuid.UUID, up | |||
} | |||
fieldValue := updatedWorkItem.Fields[fieldName] | |||
var err error | |||
if fieldName == SystemAssignees || fieldName == SystemLabels || fieldName == SystemBoardcolumns { | |||
// Remove fields with type list if there are no elements (eg: Assignee, Labels) | |||
if fieldDef.Type.GetKind() == "list" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot use fieldDef.Type.GetKind() == workitem.KindList
because it would cause a cyclic dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you can use fieldDef.Type.GetKind() == KindList
. I mean you're already in the workitem
package. So no need to import it again ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See ee41af2
I should've seen that earlier :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wait with this PR until my changes to the field types are being made.
workitem/workitem_repository.go
Outdated
if fieldDef.Type.GetKind() == "list" { | ||
switch fieldValue.(type) { | ||
case []string: | ||
if len(fieldValue.([]string)) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will change soon and you will no longer be able to case to []string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jarifibrahim it looks like the changes you've made only proof that a reorder has no effect on the event list. Is that true?
@@ -379,6 +379,14 @@ func (s *eventRepoBlackBoxTest) TestList() { | |||
assert.Equal(t, 2, c) | |||
}) | |||
|
|||
s.T().Run("reorder event shouldn't be logged", func(t *testing.T) { | |||
fxt := tf.NewTestFixture(t, s.DB, tf.WorkItems(2)) | |||
s.wiRepo.Reorder(s.Ctx, fxt.Spaces[0].ID, workitem.DirectionBelow, &fxt.WorkItems[0].ID, *fxt.WorkItems[1], fxt.Identities[0].ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please create 3 events and then move item with ID 1 to down or up? I don't know straight away if item 0 is at the top or the bottom of a list. And I bet there will not be an event if the order has no effect, say because the item is already at the very end of the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this makes it more clear 74feeca
@@ -554,6 +554,21 @@ func (r *GormWorkItemRepository) Reorder(ctx context.Context, spaceID uuid.UUID, | |||
continue | |||
} | |||
fieldValue := wi.Fields[fieldName] | |||
// Remove Assignee/Labels/Boardcolumns (fields with kind list) if they do not have a value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the comment just for clarity.
@@ -594,7 +609,8 @@ func (r *GormWorkItemRepository) Save(ctx context.Context, spaceID uuid.UUID, up | |||
} | |||
fieldValue := updatedWorkItem.Fields[fieldName] | |||
var err error | |||
if fieldName == SystemAssignees || fieldName == SystemLabels || fieldName == SystemBoardcolumns { | |||
// Remove fields with type list if there are no elements (eg: Assignee, Labels) | |||
if fieldDef.Type.GetKind() == KindList { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making this change. Yesterday I've talked about this exact line with @xcoulon and we temporarily changed it to the exact line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're welcome
No. We were generating invalid events when a workitem was reordered. With this change https://github.com/fabric8-services/fabric8-wit/pull/2196/files#diff-55f2da878ed2fcb42e5373010f02ff92R558 we will no longer have invalid events. |
workitem/workitem_repository.go
Outdated
if fieldDef.Type.GetKind() == KindList { | ||
switch fieldValue.(type) { | ||
case []string: | ||
if len(fieldValue.([]string)) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try switch t := fieldValue.(type) {
and then use if len(t) == 0 {
here so you can avoid the type assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 075a72c
The actual issue will be fixed by #2261 . |
Part of #2192
The reorder event updated the workitem such that the fields with kind list get a value of
[]
(empty list) and when the next Patch request is made theseempty values
are removed which creates an event log.This PR fixes this issue.