Class: Gitlab::Email::Handler::CreateNoteOnIssuableHandler

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

Constant Summary collapse

HANDLER_REGEX =
/\A#{HANDLER_ACTION_BASE_REGEX}-(?<incoming_email_token>.+)-issue-(?<issuable_iid>\d+)\z/.freeze

Instance Attribute Summary collapse

Attributes inherited from BaseHandler

#mail, #mail_key

Instance Method Summary collapse

Methods included from ReplyProcessing

#project

Methods inherited from BaseHandler

#metrics_params

Constructor Details

#initialize(mail, mail_key) ⇒ CreateNoteOnIssuableHandler

Returns a new instance of CreateNoteOnIssuableHandler.


20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/email/handler/create_note_on_issuable_handler.rb', line 20

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

  if (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]
    @issuable_iid         = matched[:issuable_iid]&.to_i
  end
end

Instance Attribute Details

#issuable_iidObject (readonly)

Returns the value of attribute issuable_iid.


16
17
18
# File 'lib/gitlab/email/handler/create_note_on_issuable_handler.rb', line 16

def issuable_iid
  @issuable_iid
end

Instance Method Details

#can_handle?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/gitlab/email/handler/create_note_on_issuable_handler.rb', line 31

def can_handle?
  incoming_email_token && project_id && issuable_iid
end

#executeObject

Raises:


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/email/handler/create_note_on_issuable_handler.rb', line 35

def execute
  raise ProjectNotFound unless project

  validate_permission!(:create_note)

  raise NoteableNotFoundError unless noteable
  raise EmptyEmailError if message_including_reply.blank?

  verify_record!(
    record: create_note,
    invalid_exception: InvalidNoteError,
    record_name: 'comment')
end

#metrics_eventObject


49
50
51
# File 'lib/gitlab/email/handler/create_note_on_issuable_handler.rb', line 49

def metrics_event
  :receive_email_create_note_issuable
end

#noteableObject


53
54
55
56
57
# File 'lib/gitlab/email/handler/create_note_on_issuable_handler.rb', line 53

def noteable
  return unless issuable_iid

  @noteable ||= project&.issues&.find_by_iid(issuable_iid)
end