Class: Gitlab::Email::Handler::ServiceDeskHandler

Inherits:
BaseHandler
  • Object
show all
Includes:
ReplyProcessing, Utils::StrongMemoize
Defined in:
lib/gitlab/email/handler/service_desk_handler.rb

Constant Summary collapse

HANDLER_REGEX =
/\A#{HANDLER_ACTION_BASE_REGEX}-issue-\z/.freeze
HANDLER_REGEX_LEGACY =
/\A(?<project_path>[^\+]*)\z/.freeze
PROJECT_KEY_PATTERN =
/\A(?<slug>.+)-(?<key>[a-z0-9_]+)\z/.freeze

Instance Attribute Summary

Attributes inherited from BaseHandler

#mail, #mail_key

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(mail, mail_key, service_desk_key: nil) ⇒ ServiceDeskHandler

Returns a new instance of ServiceDeskHandler.


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/email/handler/service_desk_handler.rb', line 17

def initialize(mail, mail_key, service_desk_key: nil)
  super(mail, mail_key)

  if service_desk_key.present?
    @service_desk_key = service_desk_key
  elsif !mail_key&.include?('/') && (matched = HANDLER_REGEX.match(mail_key.to_s))
    @project_slug = matched[:project_slug]
    @project_id   = matched[:project_id]&.to_i
  elsif matched = HANDLER_REGEX_LEGACY.match(mail_key.to_s)
    @project_path = matched[:project_path]
  end
end

Instance Method Details

#can_handle?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'lib/gitlab/email/handler/service_desk_handler.rb', line 30

def can_handle?
  Gitlab::ServiceDesk.supported? && (project_id || can_handle_legacy_format? || service_desk_key)
end

#executeObject

Raises:


34
35
36
37
38
39
# File 'lib/gitlab/email/handler/service_desk_handler.rb', line 34

def execute
  raise ProjectNotFound if project.nil?

  create_issue!
  send_thank_you_email! if from_address
end

#metrics_eventObject


45
46
47
# File 'lib/gitlab/email/handler/service_desk_handler.rb', line 45

def metrics_event
  :receive_email_service_desk
end

#metrics_paramsObject


41
42
43
# File 'lib/gitlab/email/handler/service_desk_handler.rb', line 41

def metrics_params
  super.merge(project: project&.full_path)
end