Commit 0140e7aa authored by Ruben Davila's avatar Ruben Davila

Add system note when time spent for Issue/MergeRequest has changed.

parent ac0358b5
...@@ -41,6 +41,11 @@ class IssuableBaseService < BaseService ...@@ -41,6 +41,11 @@ class IssuableBaseService < BaseService
issuable, issuable.project, current_user, issuable.time_estimate) issuable, issuable.project, current_user, issuable.time_estimate)
end end
def create_time_spent_note(issuable, time_spent)
SystemNoteService.change_time_spent(
issuable, issuable.project, current_user, time_spent)
end
def filter_params(issuable_ability_name = :issue) def filter_params(issuable_ability_name = :issue)
filter_assignee filter_assignee
filter_milestone filter_milestone
...@@ -235,13 +240,15 @@ class IssuableBaseService < BaseService ...@@ -235,13 +240,15 @@ class IssuableBaseService < BaseService
end end
def change_spent_time(issuable) def change_spent_time(issuable)
time_spent = params.delete(:time_spent)
if time_spent if time_spent
issuable.timelogs.new(time_spent: time_spent) issuable.timelogs.new(time_spent: time_spent)
end end
end end
def time_spent
@time_spent ||= params.delete(:time_spent)
end
def has_changes?(issuable, old_labels: []) def has_changes?(issuable, old_labels: [])
valid_attrs = [:title, :description, :assignee_id, :milestone_id, :target_branch] valid_attrs = [:title, :description, :assignee_id, :milestone_id, :target_branch]
...@@ -263,6 +270,14 @@ class IssuableBaseService < BaseService ...@@ -263,6 +270,14 @@ class IssuableBaseService < BaseService
create_task_status_note(issuable) create_task_status_note(issuable)
end end
if issuable.previous_changes.include?('time_estimate')
create_time_estimate_note(issuable)
end
if time_spent
create_time_spent_note(issuable, time_spent)
end
create_labels_note(issuable, old_labels) if issuable.labels != old_labels create_labels_note(issuable, old_labels) if issuable.labels != old_labels
end end
end end
...@@ -28,10 +28,6 @@ module Issues ...@@ -28,10 +28,6 @@ module Issues
create_confidentiality_note(issue) create_confidentiality_note(issue)
end end
if issue.previous_changes.include?('time_estimate')
create_time_estimate_note(issue)
end
added_labels = issue.labels - old_labels added_labels = issue.labels - old_labels
if added_labels.present? if added_labels.present?
notification_service.relabeled_issue(issue, added_labels, current_user) notification_service.relabeled_issue(issue, added_labels, current_user)
......
...@@ -254,11 +254,7 @@ module SlashCommands ...@@ -254,11 +254,7 @@ module SlashCommands
current_user.can?(:"admin_#{issuable.to_ability_name}", project) current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end end
command :estimate do |raw_duration| command :estimate do |raw_duration|
begin @updates[:time_estimate] = ChronicDuration.parse(raw_duration, default_unit: 'hours')
@updates[:time_estimate] = ChronicDuration.parse(raw_duration, default_unit: 'hours')
rescue ChronicDuration::DurationParseError
# do nothing
end
end end
desc 'Enter current spent time' desc 'Enter current spent time'
...@@ -268,15 +264,11 @@ module SlashCommands ...@@ -268,15 +264,11 @@ module SlashCommands
current_user.can?(:"update_#{issuable.to_ability_name}", issuable) current_user.can?(:"update_#{issuable.to_ability_name}", issuable)
end end
command :spend do |raw_duration| command :spend do |raw_duration|
begin reduce_time = raw_duration.gsub!(/\A-/, '')
reduce_time = raw_duration.gsub!(/\A-/, '') time_spent = ChronicDuration.parse(raw_duration, default_unit: 'hours')
time_spent = ChronicDuration.parse(raw_duration, default_unit: 'hours') time_spent = time_spent * -1 if reduce_time
time_spent = time_spent * -1 if reduce_time
@updates[:time_spent] = time_spent
@updates[:time_spent] = time_spent
rescue ChronicDuration::DurationParseError
# do nothing
end
end end
def find_label_ids(labels_param) def find_label_ids(labels_param)
......
...@@ -113,10 +113,10 @@ module SystemNoteService ...@@ -113,10 +113,10 @@ module SystemNoteService
# Called when the estimated time of a Noteable is changed # Called when the estimated time of a Noteable is changed
# #
# noteable - Noteable object # noteable - Noteable object
# project - Project owning noteable # project - Project owning noteable
# author - User performing the change # author - User performing the change
# milestone - Milestone being assigned, or nil # time_estimate - Estimated time
# #
# Example Note text: # Example Note text:
# #
...@@ -131,6 +131,26 @@ module SystemNoteService ...@@ -131,6 +131,26 @@ module SystemNoteService
create_note(noteable: noteable, project: project, author: author, note: body) create_note(noteable: noteable, project: project, author: author, note: body)
end end
# Called when the spent time of a Noteable is changed
#
# noteable - Noteable object
# project - Project owning noteable
# author - User performing the change
# time_spent - Spent time
#
# Example Note text:
#
# "Added 2h 30m of time spent on this issue"
#
# Returns the created Note object
def change_time_spent(noteable, project, author, time_spent)
parsed_time = ChronicDuration.output(time_spent, format: :short)
body = "Added #{parsed_time} of time spent on this #{noteable.to_ability_name}"
create_note(noteable: noteable, project: project, author: author, note: body)
end
# Called when the status of a Noteable is changed # Called when the status of a Noteable is changed
# #
# noteable - Noteable object # noteable - Noteable object
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment