diff options
Diffstat (limited to 'app/services/todo_service.rb')
-rw-r--r-- | app/services/todo_service.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index a3db2ae7947..0eb099753cb 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -8,6 +8,7 @@ # TodoService.new.new_issue(issue, current_user) # class TodoService + include Gitlab::Utils::UsageData # When create an issue we should: # # * create a todo for assignee if issue is assigned @@ -57,6 +58,14 @@ class TodoService create_assignment_todo(issuable, current_user, old_assignees) end + # When we reassign an reviewable object (merge request) we should: + # + # * create a pending todo for new reviewer if object is assigned + # + def reassigned_reviewable(issuable, current_user, old_reviewers = []) + create_reviewer_todo(issuable, current_user, old_reviewers) + end + # When create a merge request we should: # # * creates a pending todo for assignee if merge request is assigned @@ -209,6 +218,9 @@ class TodoService Array(users).map do |user| next if pending_todos(user, attributes).exists? + issue_type = attributes.delete(:issue_type) + track_todo_creation(user, issue_type) + todo = Todo.create(attributes.merge(user_id: user.id)) user.update_todos_count_cache todo @@ -217,6 +229,7 @@ class TodoService def new_issuable(issuable, author) create_assignment_todo(issuable, author) + create_reviewer_todo(issuable, author) if issuable.allows_reviewers? create_mention_todos(issuable.project, issuable, author) end @@ -250,6 +263,14 @@ class TodoService end end + def create_reviewer_todo(target, author, old_reviewers = []) + if target.reviewers.any? + reviewers = target.reviewers - old_reviewers + attributes = attributes_for_todo(target.project, target, author, Todo::REVIEW_REQUESTED) + create_todos(reviewers, attributes) + end + end + def create_mention_todos(parent, target, author, note = nil, skip_users = []) # Create Todos for directly addressed users directly_addressed_users = filter_directly_addressed_users(parent, note || target, author, skip_users) @@ -282,6 +303,8 @@ class TodoService if target.is_a?(Commit) attributes.merge!(target_id: nil, commit_id: target.id) + elsif target.is_a?(Issue) + attributes[:issue_type] = target.issue_type end attributes @@ -329,6 +352,12 @@ class TodoService def pending_todos(user, criteria = {}) PendingTodosFinder.new(user, criteria).execute end + + def track_todo_creation(user, issue_type) + return unless issue_type == 'incident' + + track_usage_event(:incident_management_incident_todo, user.id) + end end TodoService.prepend_if_ee('EE::TodoService') |