Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Do not generate event log for reorder event #2196

Closed
wants to merge 7 commits into from

Conversation

jarifibrahim
Copy link
Member

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 these empty values are removed which creates an event log.
This PR fixes this issue.

@codecov-io
Copy link

codecov-io commented Jul 30, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@1ca1860). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2196   +/-   ##
=========================================
  Coverage          ?   69.38%           
=========================================
  Files             ?      173           
  Lines             ?    16393           
  Branches          ?        0           
=========================================
  Hits              ?    11375           
  Misses            ?     3924           
  Partials          ?     1094
Impacted Files Coverage Δ
workitem/workitem_repository.go 68.66% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ca1860...052f980. Read the comment docs.

@@ -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" {
Copy link
Member Author

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.

Copy link
Collaborator

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 ;)

Copy link
Member Author

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 :)

@@ -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" {
Copy link
Member Author

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.

Copy link
Collaborator

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 ;)

Copy link
Member Author

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 :)

Copy link
Collaborator

@kwk kwk left a 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.

if fieldDef.Type.GetKind() == "list" {
switch fieldValue.(type) {
case []string:
if len(fieldValue.([]string)) == 0 {
Copy link
Collaborator

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.

Copy link
Collaborator

@kwk kwk left a 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)
Copy link
Collaborator

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.

Copy link
Member Author

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
Copy link
Collaborator

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?

Copy link
Member Author

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 {
Copy link
Collaborator

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're welcome

@jarifibrahim
Copy link
Member Author

it looks like the changes you've made only proof that a reorder has no effect on the event list. Is that true?

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.

if fieldDef.Type.GetKind() == KindList {
switch fieldValue.(type) {
case []string:
if len(fieldValue.([]string)) == 0 {
Copy link
Collaborator

@kwk kwk Aug 27, 2018

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 075a72c

@jarifibrahim
Copy link
Member Author

The actual issue will be fixed by #2261 .
Closing this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants