Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-05-21 19:40:08 +0300
committerLin Jen-Shin <godfat@godfat.org>2016-05-21 19:40:08 +0300
commit75415663f84ac006c5a4d5a6896ece50c299c03e (patch)
treee263b7dc9aca0200eeb14e079e7dda69e7aad3c8 /lib/gitlab/email/handler/create_issue_handler.rb
parentee548b6ed0e8f885cdd7dfcc104ea1471ad62bd0 (diff)
Rename handlers and introduce Handler.for
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