Commit c32e364c authored by Ruben Davila's avatar Ruben Davila

Add new slash command to log spent time for Issues/MergeRequests.

parent bf13fa05
......@@ -177,6 +177,7 @@ class IssuableBaseService < BaseService
change_state(issuable)
change_subscription(issuable)
change_todo(issuable)
change_spent_time(issuable)
filter_params
old_labels = issuable.labels.to_a
old_mentioned_users = issuable.mentioned_users.to_a
......@@ -228,6 +229,14 @@ class IssuableBaseService < BaseService
end
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 has_changes?(issuable, old_labels: [])
valid_attrs = [:title, :description, :assignee_id, :milestone_id, :target_branch]
......
......@@ -249,7 +249,7 @@ module SlashCommands
command :cc
desc 'Set estimate'
params 'e.g: 3h 30m'
params 'e.g: 1w 3d 2h 14m'
condition do
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end
......@@ -261,6 +261,20 @@ module SlashCommands
end
end
desc 'Enter current spent time'
params 'e.g: 3h 30m'
condition do
issuable.persisted? &&
current_user.can?(:"update_#{issuable.to_ability_name}", issuable)
end
command :spend do |raw_duration|
begin
@updates[:time_spent] = ChronicDuration.parse(raw_duration, default_unit: 'hours')
rescue ChronicDuration::DurationParseError
# do nothing
end
end
def find_label_ids(labels_param)
label_ids_by_reference = extract_references(labels_param, :label).map(&:id)
labels_ids_by_name = LabelsFinder.new(current_user, project_id: project.id, name: labels_param.split).execute.select(:id)
......
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