diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/services/issuable_base_service.rb | 2 | ||||
-rw-r--r-- | app/services/issues/update_service.rb | 23 | ||||
-rw-r--r-- | app/services/merge_requests/update_service.rb | 2 | ||||
-rw-r--r-- | app/services/task_service.rb | 13 |
4 files changed, 37 insertions, 3 deletions
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index 2556f06e2d3..63025c10fb0 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -54,7 +54,7 @@ class IssuableBaseService < BaseService if params.present? && issuable.update_attributes(params.merge(updated_by: current_user)) issuable.reset_events_cache handle_common_system_notes(issuable, old_labels: old_labels) - handle_changes(issuable) + handle_changes(issuable, old_labels: old_labels) issuable.create_new_cross_references!(current_user) execute_hooks(issuable, 'update') end diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index e6afcb91652..fb9571247cc 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -4,7 +4,11 @@ module Issues update(issue) end - def handle_changes(issue) + def handle_changes(issue, options = {}) + if have_changes?(issue, options) + task_service.mark_as_done(issue, current_user) + end + if issue.previous_changes.include?('milestone_id') create_milestone_note(issue) end @@ -23,5 +27,22 @@ module Issues def close_service Issues::CloseService end + + private + + def have_changes?(issue, options = {}) + valid_attrs = [:title, :description, :assignee_id, :milestone_id] + + attrs_changed = valid_attrs.any? do |attr| + issue.previous_changes.include?(attr.to_s) + end + + old_labels = options[:old_labels] + labels_changed = old_labels && issue.labels != old_labels + + if attrs_changed || labels_changed + task_service.mark_as_done(issue, current_user) + end + end end end diff --git a/app/services/merge_requests/update_service.rb b/app/services/merge_requests/update_service.rb index 5ff2cc03dda..55322bf47bb 100644 --- a/app/services/merge_requests/update_service.rb +++ b/app/services/merge_requests/update_service.rb @@ -14,7 +14,7 @@ module MergeRequests update(merge_request) end - def handle_changes(merge_request) + def handle_changes(merge_request, options = {}) if merge_request.previous_changes.include?('target_branch') create_branch_change_note(merge_request, 'target', merge_request.previous_changes['target_branch'].first, diff --git a/app/services/task_service.rb b/app/services/task_service.rb index 35d258a70c2..2c312331ae9 100644 --- a/app/services/task_service.rb +++ b/app/services/task_service.rb @@ -26,6 +26,15 @@ class TaskService end end + # When we mark a task as done we should: + # + # * mark all pending tasks related to the target for the user as done + # + def mark_as_done(target, user) + pending_tasks = pending_tasks_for(user, target.project, target) + pending_tasks.update_all(state: :done) + end + private def create_task(project, target, author, user, action) @@ -40,4 +49,8 @@ class TaskService Task.create(attributes) end + + def pending_tasks_for(user, project, target) + user.tasks.pending.where(project: project, target: target) + end end |