diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-08-12 20:17:18 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-08-12 20:17:18 -0500 |
commit | 5a07b760dff04660d9c7da84852c710b1fc2f786 (patch) | |
tree | 6aa67c32c6b80dcc1c7cbfe4f9f62e57edb76b3e /app/services/notes | |
parent | 5d4993d62357e438b6211247278025040f3ae382 (diff) | |
download | gitlab-ce-5a07b760dff04660d9c7da84852c710b1fc2f786.tar.gz |
Refactor slash command definition
Diffstat (limited to 'app/services/notes')
-rw-r--r-- | app/services/notes/create_service.rb | 6 | ||||
-rw-r--r-- | app/services/notes/slash_commands_service.rb | 11 |
2 files changed, 9 insertions, 8 deletions
diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index 1b2d63034b8..f7cf4a8edc0 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -15,7 +15,9 @@ module Notes # **before** we save the note because if the note consists of commands # only, there is no need be create a note! slash_commands_service = SlashCommandsService.new(project, current_user) - commands = slash_commands_service.extract_commands(note) + content, command_params = slash_commands_service.extract_commands(note) + + note.note = content if note.save # Finish the harder work in the background @@ -25,7 +27,7 @@ module Notes # We must add the error after we call #save because errors are reset # when #save is called - if slash_commands_service.execute(commands, note) && note.note.blank? + if slash_commands_service.execute(command_params, note) && note.note.blank? note.errors.add(:commands_only, 'Your commands are being executed.') end diff --git a/app/services/notes/slash_commands_service.rb b/app/services/notes/slash_commands_service.rb index ebced9577d8..f2c43775b72 100644 --- a/app/services/notes/slash_commands_service.rb +++ b/app/services/notes/slash_commands_service.rb @@ -1,6 +1,5 @@ module Notes class SlashCommandsService < BaseService - UPDATE_SERVICES = { 'Issue' => Issues::UpdateService, 'MergeRequest' => MergeRequests::UpdateService @@ -15,11 +14,11 @@ module Notes execute(note.note, note.noteable) end - def execute(commands, note) - if commands.any? - @noteable_update_service.new(project, current_user, commands). - execute(note.noteable) - end + def execute(command_params, note) + return if command_params.empty? + + @noteable_update_service.new(project, current_user, command_params). + execute(note.noteable) end end end |