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
issuable, issuable.project, current_user, issuable.time_estimate)
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)
filter_assignee
filter_milestone
......@@ -235,13 +240,15 @@ class IssuableBaseService < BaseService
end
def change_spent_time(issuable)
time_spent = params.delete(:time_spent)
if time_spent
issuable.timelogs.new(time_spent: time_spent)
end
end
def time_spent
@time_spent ||= params.delete(:time_spent)
end
def has_changes?(issuable, old_labels: [])
valid_attrs = [:title, :description, :assignee_id, :milestone_id, :target_branch]
......@@ -263,6 +270,14 @@ class IssuableBaseService < BaseService
create_task_status_note(issuable)
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
end
end
......@@ -28,10 +28,6 @@ module Issues
create_confidentiality_note(issue)
end
if issue.previous_changes.include?('time_estimate')
create_time_estimate_note(issue)
end
added_labels = issue.labels - old_labels
if added_labels.present?
notification_service.relabeled_issue(issue, added_labels, current_user)
......
......@@ -254,11 +254,7 @@ module SlashCommands
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end
command :estimate do |raw_duration|
begin
@updates[:time_estimate] = ChronicDuration.parse(raw_duration, default_unit: 'hours')
rescue ChronicDuration::DurationParseError
# do nothing
end
end
desc 'Enter current spent time'
......@@ -268,15 +264,11 @@ module SlashCommands
current_user.can?(:"update_#{issuable.to_ability_name}", issuable)
end
command :spend do |raw_duration|
begin
reduce_time = raw_duration.gsub!(/\A-/, '')
time_spent = ChronicDuration.parse(raw_duration, default_unit: 'hours')
time_spent = time_spent * -1 if reduce_time
@updates[:time_spent] = time_spent
rescue ChronicDuration::DurationParseError
# do nothing
end
end
def find_label_ids(labels_param)
......
......@@ -116,7 +116,7 @@ module SystemNoteService
# noteable - Noteable object
# project - Project owning noteable
# author - User performing the change
# milestone - Milestone being assigned, or nil
# time_estimate - Estimated time
#
# Example Note text:
#
......@@ -131,6 +131,26 @@ module SystemNoteService
create_note(noteable: noteable, project: project, author: author, note: body)
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
#
# 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