diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-05-21 19:40:08 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-05-21 19:40:08 +0300 |
commit | 75415663f84ac006c5a4d5a6896ece50c299c03e (patch) | |
tree | e263b7dc9aca0200eeb14e079e7dda69e7aad3c8 /lib/gitlab/email/handler/create_issue_handler.rb | |
parent | ee548b6ed0e8f885cdd7dfcc104ea1471ad62bd0 (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.rb | 50 |
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 |