diff options
author | Felipe Artur <fcardozo@gitlab.com> | 2019-03-04 12:21:47 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-03-04 12:21:47 +0300 |
commit | 78dc1b58a64be03e6d3622aab5605e1d5f6a6643 (patch) | |
tree | d0dd8c328bb0c7ce2311c79f525f7f23db9e0ff0 /app/services/notes | |
parent | 4b0036b87ee30ce0a3687dd052514b571f4d520f (diff) |
Show commands applied message when promoting issues
Fix 'commands applied' messages not being shown when issue is promoted to epic
using slash commands.
Diffstat (limited to 'app/services/notes')
-rw-r--r-- | app/services/notes/create_service.rb | 11 | ||||
-rw-r--r-- | app/services/notes/quick_actions_service.rb | 26 |
2 files changed, 26 insertions, 11 deletions
diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index 5a6e7338b42..1b46f6d8a72 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -21,7 +21,7 @@ module Notes if quick_actions_service.supported?(note) options = { merge_request_diff_head_sha: merge_request_diff_head_sha } - content, command_params = quick_actions_service.extract_commands(note, options) + content, update_params = quick_actions_service.execute(note, options) only_commands = content.empty? @@ -43,16 +43,17 @@ module Notes Suggestions::CreateService.new(note).execute end - if command_params.present? - quick_actions_service.execute(command_params, note) + if quick_actions_service.commands_executed_count.to_i > 0 + if update_params.present? + quick_actions_service.apply_updates(update_params, note) + note.commands_changes = update_params + end # We must add the error after we call #save because errors are reset # when #save is called if only_commands note.errors.add(:commands_only, 'Commands applied') end - - note.commands_changes = command_params end note diff --git a/app/services/notes/quick_actions_service.rb b/app/services/notes/quick_actions_service.rb index 985a03060bd..0852a708240 100644 --- a/app/services/notes/quick_actions_service.rb +++ b/app/services/notes/quick_actions_service.rb @@ -1,7 +1,18 @@ # frozen_string_literal: true +# QuickActionsService class +# +# Executes quick actions commands extracted from note text +# +# Most commands returns parameters to be applied later +# using QuickActionService#apply_updates +# module Notes class QuickActionsService < BaseService + attr_reader :interpret_service + + delegate :commands_executed_count, to: :interpret_service, allow_nil: true + UPDATE_SERVICES = { 'Issue' => Issues::UpdateService, 'MergeRequest' => MergeRequests::UpdateService, @@ -25,18 +36,21 @@ module Notes self.class.supported?(note) end - def extract_commands(note, options = {}) + def execute(note, options = {}) return [note.note, {}] unless supported?(note) - QuickActions::InterpretService.new(project, current_user, options) - .execute(note.note, note.noteable) + @interpret_service = QuickActions::InterpretService.new(project, current_user, options) + + @interpret_service.execute(note.note, note.noteable) end - def execute(command_params, note) - return if command_params.empty? + # Applies updates extracted to note#noteable + # The update parameters are extracted on self#execute + def apply_updates(update_params, note) + return if update_params.empty? return unless supported?(note) - self.class.noteable_update_service(note).new(note.parent, current_user, command_params).execute(note.noteable) + self.class.noteable_update_service(note).new(note.parent, current_user, update_params).execute(note.noteable) end end end |