diff options
author | Ruben Davila <rdavila84@gmail.com> | 2015-10-22 10:18:59 -0500 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2015-11-19 21:05:44 -0500 |
commit | 97afb84b310cfdaa9305e8b79fc00bdbb866bbca (patch) | |
tree | a1fb56e5458fcb655d6b7e129812edcd6093fb3c /app/models/concerns/taskable.rb | |
parent | a8e7bee3a6de05feaee2f276f6f7b35fbbd4b9e3 (diff) | |
download | gitlab-ce-97afb84b310cfdaa9305e8b79fc00bdbb866bbca.tar.gz |
Generate system note after Task item has been updated on Issue or Merge Request. #2296
Everytime the User check or uncheck a Task Item from the Issue or
Merge Request description, a new update is going to be
added to the activity logs of the Issue or Merge Request.
Note that when using the edit form, you can only update the Task item
status or add/delete/modify existing ones. Doing both actions is not
fully supported.
Diffstat (limited to 'app/models/concerns/taskable.rb')
-rw-r--r-- | app/models/concerns/taskable.rb | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/app/models/concerns/taskable.rb b/app/models/concerns/taskable.rb index 660e58b876d..3daa4dbe24e 100644 --- a/app/models/concerns/taskable.rb +++ b/app/models/concerns/taskable.rb @@ -7,14 +7,37 @@ require 'task_list/filter' # # Used by MergeRequest and Issue module Taskable + ITEM_PATTERN = / + ^ + (?:\s*[-+*]|(?:\d+\.))? # optional list prefix + \s* # optional whitespace prefix + (\[\s\]|\[[xX]\]) # checkbox + (\s.+) # followed by whitespace and some text. + /x + + def self.get_tasks(content) + content.to_s.scan(ITEM_PATTERN).map do |checkbox, label| + # ITEM_PATTERN strips out the hyphen, but Item requires it. Rabble rabble. + TaskList::Item.new("- #{checkbox}", label.strip) + end + end + + def self.get_updated_tasks(old_content:, new_content:) + old_tasks, new_tasks = get_tasks(old_content), get_tasks(new_content) + + new_tasks.select.with_index do |new_task, i| + old_task = old_tasks[i] + next unless old_task + + new_task.source == new_task.source && new_task.complete? != old_task.complete? + end + end + # Called by `TaskList::Summary` def task_list_items return [] if description.blank? - @task_list_items ||= description.scan(TaskList::Filter::ItemPattern).collect do |item| - # ItemPattern strips out the hyphen, but Item requires it. Rabble rabble. - TaskList::Item.new("- #{item}") - end + @task_list_items ||= Taskable.get_tasks(description) end def tasks |