gitlab-org--gitlab-foss/lib/gitlab/email/handler/create_issue_handler.rb

50 lines
1.1 KiB
Ruby
Raw Normal View History

require 'gitlab/email/handler/base_handler'
module Gitlab
module Email
module Handler
class CreateIssueHandler < BaseHandler
attr_reader :project_path, :authentication_token
def initialize(mail, mail_key)
super(mail, mail_key)
@project_path, @authentication_token =
mail_key && mail_key.split('+', 2)
end
def can_handle?
2016-06-15 04:15:49 -04:00
!authentication_token.nil?
end
def execute
raise ProjectNotFound unless project
validate_permission!(:create_issue)
2016-06-15 08:10:16 -04:00
verify_record!(create_issue, InvalidIssueError, 'issue')
end
def author
@author ||= User.find_by(authentication_token: authentication_token)
end
def project
@project ||= Project.find_with_namespace(project_path)
end
private
2016-06-15 07:41:31 -04:00
def create_issue
Issues::CreateService.new(
project,
author,
title: mail.subject,
description: message
).execute
end
end
end
end
end