Class: Gitlab::Email::Handler::CreateIssueHandler

Inherits:
BaseHandler
  • Object
show all
Includes:
ReplyProcessing
Defined in:
lib/gitlab/email/handler/create_issue_handler.rb

Constant Summary collapse

HANDLER_REGEX =
/\A#{HANDLER_ACTION_BASE_REGEX}-(?<incoming_email_token>.+)-issue\z/.freeze
HANDLER_REGEX_LEGACY =
/\A(?<project_path>[^\+]*)\+(?<incoming_email_token>.*)\z/.freeze

Instance Attribute Summary

Attributes inherited from BaseHandler

#mail, #mail_key

Instance Method Summary collapse

Methods inherited from BaseHandler

#metrics_params

Constructor Details

#initialize(mail, mail_key) ⇒ CreateIssueHandler

Returns a new instance of CreateIssueHandler.


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

def initialize(mail, mail_key)
  super(mail, mail_key)

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

Instance Method Details

#authorObject

rubocop: disable CodeReuse/ActiveRecord


46
47
48
# File 'lib/gitlab/email/handler/create_issue_handler.rb', line 46

def author
  @author ||= User.find_by(incoming_email_token: incoming_email_token)
end

#can_handle?Boolean

Returns:

  • (Boolean)

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

def can_handle?
  incoming_email_token && (project_id || can_handle_legacy_format?)
end

#executeObject

Raises:


34
35
36
37
38
39
40
41
42
43
# File 'lib/gitlab/email/handler/create_issue_handler.rb', line 34

def execute
  raise ProjectNotFound unless project

  validate_permission!(:create_issue)

  verify_record!(
    record: create_issue,
    invalid_exception: InvalidIssueError,
    record_name: 'issue')
end

#metrics_eventObject

rubocop: enable CodeReuse/ActiveRecord


51
52
53
# File 'lib/gitlab/email/handler/create_issue_handler.rb', line 51

def metrics_event
  :receive_email_create_issue
end