gitlab-org--gitlab-foss/lib/gitlab/email/handler/create_issue.rb
2016-05-20 17:38:08 -05:00

50 lines
1 KiB
Ruby

require 'gitlab/email/handler'
module Gitlab
module Email
class Handler
class CreateIssue < Handler
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