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

#draft_action_message, #merge_orchestration_service, #preferred_auto_merge_strategy, #reviewer_users_sentence, #reviewers_for_removal, #reviewers_to_add

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

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.



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

def commands_executed_count
  @commands_executed_count
end

#quick_action_targetObject (readonly)

Returns the value of attribute quick_action_target.



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

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



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

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.



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

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), command_names(commands)]
end

#explain(content, quick_action_target, keep_actions: false) ⇒ Object

Takes a text and interprets the commands that are extracted from it. Returns the content without commands, and array of changes explained. ‘keep_actions: true` will keep the quick actions in the content.



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

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

  @quick_action_target = quick_action_target

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