Commit 863d8e5a authored by Lin Jen-Shin's avatar Lin Jen-Shin

use split and try to unify error raising

parent c64cd113
...@@ -5,8 +5,16 @@ module Gitlab ...@@ -5,8 +5,16 @@ module Gitlab
module Email module Email
module Handler module Handler
class CreateIssueHandler < BaseHandler class CreateIssueHandler < BaseHandler
attr_reader :project_namespace, :authentication_token
def initialize(mail, mail_key)
super(mail, mail_key)
@project_namespace, @authentication_token =
mail_key && mail_key.split('+', 2)
end
def can_handle? def can_handle?
!!project !!(project_namespace && project)
end end
def execute def execute
...@@ -28,14 +36,6 @@ module Gitlab ...@@ -28,14 +36,6 @@ module Gitlab
end end
private private
def authentication_token
mail_key[/[^\+]+$/]
end
def project_namespace
mail_key[/^[^\+]+/]
end
def create_issue def create_issue
Issues::CreateService.new( Issues::CreateService.new(
project, project,
......
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
module Handler module Handler
class CreateNoteHandler < BaseHandler class CreateNoteHandler < BaseHandler
def can_handle? def can_handle?
!!sent_notification !!(mail_key && sent_notification)
end end
def execute def execute
......
...@@ -28,8 +28,6 @@ module Gitlab ...@@ -28,8 +28,6 @@ module Gitlab
mail = build_mail mail = build_mail
mail_key = extract_mail_key(mail) mail_key = extract_mail_key(mail)
raise SentNotificationNotFoundError unless mail_key
if handler = Handler.for(mail, mail_key) if handler = Handler.for(mail, mail_key)
handler.execute handler.execute
elsif mail_key =~ %r{/|\+} elsif mail_key =~ %r{/|\+}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment