diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index b60afd1560e..57286f255f4 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -193,9 +193,7 @@ class IssuableBaseService < BaseService todo_service.mark_todo(issuable, current_user) when 'done' todo = TodosFinder.new(current_user).execute.find_by(target: issuable) - if todo - todo_service.mark_todos_as_done([todo], current_user) - end + todo_service.mark_todos_as_done([todo], current_user) if todo end end diff --git a/app/services/slash_commands/interpret_service.rb b/app/services/slash_commands/interpret_service.rb index cb0dca94036..dc4a892b8b1 100644 --- a/app/services/slash_commands/interpret_service.rb +++ b/app/services/slash_commands/interpret_service.rb @@ -18,11 +18,11 @@ module SlashCommands content, commands = extractor.extract_commands(content, opts) - commands.each do |name, *args| + commands.each do |name, args| definition = self.class.command_definitions_by_name[name.to_sym] next unless definition - definition.execute(self, opts, *args) + definition.execute(self, opts, args) end [content, @updates] @@ -76,7 +76,6 @@ module SlashCommands command :assign do |assignee_param| user = extract_references(assignee_param, :user).first user ||= User.find_by(username: assignee_param) - user ||= User.find_by(name: assignee_param) @updates[:assignee_id] = user.id if user end diff --git a/lib/gitlab/slash_commands/command_definition.rb b/lib/gitlab/slash_commands/command_definition.rb index 641c92e77da..2ff8f4eddf0 100644 --- a/lib/gitlab/slash_commands/command_definition.rb +++ b/lib/gitlab/slash_commands/command_definition.rb @@ -6,11 +6,11 @@ module Gitlab def initialize(name, attributes = {}) @name = name - @aliases = attributes[:aliases] || [] - @description = attributes[:description] || '' - @params = attributes[:params] || [] - @condition_block = attributes[:condition_block] - @action_block = attributes[:action_block] + @aliases = attributes[:aliases] || [] + @description = attributes[:description] || '' + @params = attributes[:params] || [] + @condition_block = attributes[:condition_block] + @action_block = attributes[:action_block] end def all_names @@ -28,13 +28,13 @@ module Gitlab context.instance_exec(&condition_block) end - def execute(context, opts, *args) + def execute(context, opts, args) return if noop? || !available?(opts) block_arity = action_block.arity - return unless block_arity == -1 || block_arity == args.size + return unless (args.present? && block_arity == 1) || (args.blank? && block_arity <= 0) - context.instance_exec(*args, &action_block) + context.instance_exec(args, &action_block) end def to_h(opts) diff --git a/lib/gitlab/slash_commands/extractor.rb b/lib/gitlab/slash_commands/extractor.rb index 02c4c8c492e..c790b825347 100644 --- a/lib/gitlab/slash_commands/extractor.rb +++ b/lib/gitlab/slash_commands/extractor.rb @@ -50,15 +50,6 @@ module Gitlab end private - - def command_names(opts) - command_definitions.flat_map do |command| - next if command.noop? - - command.all_names - end.compact - end - # Builds a regular expression to match known commands. # First match group captures the command name and # second match group captures its arguments. @@ -117,6 +108,14 @@ module Gitlab ) }mx end + + def command_names(opts) + command_definitions.flat_map do |command| + next if command.noop? + + command.all_names + end.compact + end end end end