Class: QuickActions::InterpretService
- Inherits:
-
BaseContainerService
- Object
- BaseContainerService
- QuickActions::InterpretService
- Includes:
- Gitlab::QuickActions::CommitActions, Gitlab::QuickActions::Dsl, Gitlab::QuickActions::IssuableActions, Gitlab::QuickActions::IssueActions, Gitlab::QuickActions::IssueAndMergeRequestActions, Gitlab::QuickActions::MergeRequestActions, Gitlab::QuickActions::RelateActions, Gitlab::QuickActions::WorkItemActions, Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/quick_actions/interpret_service.rb
Constant Summary collapse
- QuickActionsNotAllowedError =
Class.new(StandardError)
Constants included from Gitlab::QuickActions::MergeRequestActions
Gitlab::QuickActions::MergeRequestActions::REBASE_FAILURE_PROTECTED_BRANCH, Gitlab::QuickActions::MergeRequestActions::REBASE_FAILURE_REBASE_IN_PROGRESS, Gitlab::QuickActions::MergeRequestActions::REBASE_FAILURE_UNMERGEABLE
Constants included from Gitlab::QuickActions::IssuableActions
Gitlab::QuickActions::IssuableActions::SHRUG, Gitlab::QuickActions::IssuableActions::TABLEFLIP
Instance Attribute Summary collapse
-
#commands_executed_count ⇒ Object
Counts how many commands have been executed.
-
#quick_action_target ⇒ Object
readonly
Returns the value of attribute quick_action_target.
Attributes inherited from BaseContainerService
#container, #current_user, #group, #params, #project
Instance Method Summary collapse
-
#available_commands(quick_action_target) ⇒ Object
Takes an quick_action_target and returns an array of all the available commands represented with .to_h.
-
#execute(content, quick_action_target, only: nil) ⇒ Object
IMPORTANT: unsafe! Use
execute_with_original_textinstead as it handles cleanup of any residual quick actions left in the original description. -
#execute_with_original_text(new_text, quick_action_target, only: nil, original_text: nil) ⇒ Object
Similar to
executeexcept also tries to extract any quick actions from original_text, and if found removes them from the main list of quick actions. -
#explain(content, quick_action_target, keep_actions: false) ⇒ Object
Takes a text and interprets the commands that are extracted from it.
Methods included from Gitlab::QuickActions::RelateActions
Methods included from Gitlab::QuickActions::MergeRequestActions
#auto_merge_strategy_copy, #create_pipeline_service, #draft_action_message, #merge_orchestration_service, #preferred_auto_merge_strategy, #process_reviewer_users, #process_reviewer_users_message, #reviewer_users_sentence, #reviewers_for_removal, #reviewers_to_add, #reviewers_to_remove?
Methods inherited from BaseContainerService
#group_container?, #initialize, #namespace_container?, #project_container?, #project_group, #root_ancestor
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
Constructor Details
This class inherits a constructor from BaseContainerService
Instance Attribute Details
#commands_executed_count ⇒ Object
Counts how many commands have been executed. Used to display relevant feedback on UI when a note with only commands has been processed.
22 23 24 |
# File 'app/services/quick_actions/interpret_service.rb', line 22 def commands_executed_count @commands_executed_count end |
#quick_action_target ⇒ Object (readonly)
Returns the value of attribute quick_action_target.
17 18 19 |
# File 'app/services/quick_actions/interpret_service.rb', line 17 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
26 27 28 29 30 31 32 33 34 |
# File 'app/services/quick_actions/interpret_service.rb', line 26 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
IMPORTANT: unsafe! Use execute_with_original_text instead as it handles cleanup of any residual quick actions left in the original description.
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.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/services/quick_actions/interpret_service.rb', line 42 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 = {} @additional_properties = {} content, commands = extractor.extract_commands(content, only: only) extract_updates(commands) [content, @updates, (commands), command_names(commands)] end |
#execute_with_original_text(new_text, quick_action_target, only: nil, original_text: nil) ⇒ Object
Similar to execute except also tries to extract any quick actions from original_text, and if found removes them from the main list of quick actions.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/services/quick_actions/interpret_service.rb', line 58 def execute_with_original_text(new_text, quick_action_target, only: nil, original_text: nil) sanitized_new_text, new_command_params, , command_names = execute( new_text, quick_action_target, only: only ) if original_text _, original_command_params = self.class.new( container: container, current_user: current_user, params: params ).execute(original_text, quick_action_target, only: only) new_command_params = (new_command_params.to_a - original_command_params.to_a).to_h if original_command_params end [sanitized_new_text, new_command_params, , command_names] 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.
79 80 81 82 83 84 85 86 87 |
# File 'app/services/quick_actions/interpret_service.rb', line 79 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 |