summaryrefslogtreecommitdiff
path: root/lib/gitlab/email/handler/create_issue_handler.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/email/handler/create_issue_handler.rb')
-rw-r--r--lib/gitlab/email/handler/create_issue_handler.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/gitlab/email/handler/create_issue_handler.rb b/lib/gitlab/email/handler/create_issue_handler.rb
new file mode 100644
index 00000000000..259d74a83bf
--- /dev/null
+++ b/lib/gitlab/email/handler/create_issue_handler.rb
@@ -0,0 +1,50 @@
+
+require 'gitlab/email/handler/base_handler'
+
+module Gitlab
+ module Email
+ module Handler
+ class CreateIssueHandler < BaseHandler
+ def can_handle?
+ !!project
+ end
+
+ def execute
+ validate_permission!(:create_issue)
+
+ verify_record(
+ create_issue,
+ InvalidIssueError,
+ "The issue could not be created for the following reasons:"
+ )
+ end
+
+ def author
+ @author ||= User.find_by(authentication_token: authentication_token)
+ end
+
+ def project
+ @project ||= Project.find_with_namespace(project_namespace)
+ end
+
+ private
+ def authentication_token
+ mail_key[/[^\+]+$/]
+ end
+
+ def project_namespace
+ mail_key[/^[^\+]+/]
+ end
+
+ def create_issue
+ Issues::CreateService.new(
+ project,
+ author,
+ title: mail.subject,
+ description: message
+ ).execute
+ end
+ end
+ end
+ end
+end