Skip to content

Commit

Permalink
Fixed isDirty structural inconsistency in onStateChange().
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkleinhenz committed Aug 28, 2018
1 parent 58f5187 commit 973fe2d
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions actions/rules/action_state_to_metastate.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (act ActionStateToMetaState) fuseChanges(c1 change.Set, c2 change.Set) *cha
return &c1
}

// OnChange executes the action rule. It implements rules.Action.
// OnChange executes the action rule. It implements rules.Action. Returns the Work Item with eventual changes applied.
func (act ActionStateToMetaState) OnChange(newContext change.Detector, contextChanges change.Set, configuration string, actionChanges *change.Set) (change.Detector, change.Set, error) {
if act.Ctx == nil {
return nil, nil, errs.New("context is nil")
Expand Down Expand Up @@ -223,7 +223,7 @@ func (act ActionStateToMetaState) OnChange(newContext change.Detector, contextCh
return newContext, *actionChanges, nil
}

// onBoardColumnsChange is executed when the columns change. It eventually updates the metastate and the state.
// onBoardColumnsChange is executed when the columns change. It eventually updates the metastate and the state. Returns the Work Item with eventual changes applied.
func (act ActionStateToMetaState) onBoardColumnsChange(newContext change.Detector, contextChanges change.Set, configuration string, actionChanges *change.Set) (change.Detector, change.Set, error) {
// we already assume that the rule applies, this needs to be checked in the controller.
// there is no additional check on the rule key.
Expand Down Expand Up @@ -325,7 +325,7 @@ func (act ActionStateToMetaState) onBoardColumnsChange(newContext change.Detecto
return resultingWorkItem, changes, nil
}

// onStateChange is executed when the state changes. It eventually updates the metastate and the boardcolumns.
// onStateChange is executed when the state changes. It eventually updates the metastate and the boardcolumns. Returns the Work Item with eventual changes applied.
func (act ActionStateToMetaState) onStateChange(newContext change.Detector, contextChanges change.Set, configuration string, actionChanges *change.Set) (change.Detector, change.Set, error) {
wi, ok := newContext.(workitem.WorkItem)
if !ok {
Expand All @@ -336,9 +336,6 @@ func (act ActionStateToMetaState) onStateChange(newContext change.Detector, cont
if err != nil {
return nil, nil, err
}
// create a dirty flag. Note that we can not use len(actionChanges) as this
// may contain previous changes from the action chain.
wiDirty := false
// update the workitem accordingly.
wiState := wi.Fields[workitem.SystemState].(string)
if wi.Fields[workitem.SystemMetaState] == mapping[wiState] {
Expand All @@ -348,7 +345,6 @@ func (act ActionStateToMetaState) onStateChange(newContext change.Detector, cont
// otherwise, update the metastate from the state.
changes := act.addOrUpdateChange(*actionChanges, workitem.SystemMetaState, wi.Fields[workitem.SystemMetaState], mapping[wiState])
wi.Fields[workitem.SystemMetaState] = mapping[wiState]
wiDirty = true
// next, get the columns of the workitem and see if these needs to be updated.
boards, err := act.loadWorkItemBoardsBySpaceID(wi.SpaceID)
if err != nil {
Expand Down Expand Up @@ -455,12 +451,10 @@ func (act ActionStateToMetaState) onStateChange(newContext change.Detector, cont
}
// finally, store the new work item state if something changed.
var resultingWorkItem workitem.WorkItem
if wiDirty {
result, err := act.storeWorkItem(&wi)
resultingWorkItem = *result
if err != nil {
return nil, nil, err
}
result, err := act.storeWorkItem(&wi)
resultingWorkItem = *result
if err != nil {
return nil, nil, err
}
// and return to sender.
return resultingWorkItem, changes, nil
Expand Down

0 comments on commit 973fe2d

Please sign in to comment.