Class: QuickActions::InterpretService

Constant Summary

Constants included from Gitlab::QuickActions::IssuableActions

Gitlab::QuickActions::IssuableActions::SHRUG, Gitlab::QuickActions::IssuableActions::TABLEFLIP

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::QuickActions::MergeRequestActions

#merge_orchestration_service, #preferred_auto_merge_strategy

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Attribute Details

#commands_executed_countObject

Counts how many commands have been executed. Used to display relevant feedback on UI when a note with only commands has been processed.


20
21
22
# File 'app/services/quick_actions/interpret_service.rb', line 20

def commands_executed_count
  @commands_executed_count
end

#quick_action_targetObject (readonly)

Returns the value of attribute quick_action_target


15
16
17
# File 'app/services/quick_actions/interpret_service.rb', line 15

def quick_action_target
  @quick_action_target
end

Instance Method Details

#available_commands(quick_action_target) ⇒ Object

Takes an quick_action_target and returns an array of all the available commands represented with .to_h


24
25
26
27
28
29
30
31
32
# File 'app/services/quick_actions/interpret_service.rb', line 24

def available_commands(quick_action_target)
  @quick_action_target = quick_action_target

  self.class.command_definitions.map do |definition|
    next unless definition.available?(self)

    definition.to_h(self)
  end.compact
end

#execute(content, quick_action_target, only: nil) ⇒ Object

Takes a text and interprets the commands that are extracted from it. Returns the content without commands, a hash of changes to be applied to a record and a string containing the execution_message to show to the user.


37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/quick_actions/interpret_service.rb', line 37

def execute(content, quick_action_target, only: nil)
  return [content, {}, ''] unless current_user.can?(:use_quick_actions)

  @quick_action_target = quick_action_target
  @updates = {}
  @execution_message = {}

  content, commands = extractor.extract_commands(content, only: only)
  extract_updates(commands)

  [content, @updates, execution_messages_for(commands)]
end

#explain(content, quick_action_target) ⇒ Object

Takes a text and interprets the commands that are extracted from it. Returns the content without commands, and array of changes explained.


52
53
54
55
56
57
58
59
60
# File 'app/services/quick_actions/interpret_service.rb', line 52

def explain(content, quick_action_target)
  return [content, []] unless current_user.can?(:use_quick_actions)

  @quick_action_target = quick_action_target

  content, commands = extractor.extract_commands(content)
  commands = explain_commands(commands)
  [content, commands]
end