debian-mirror-gitlab/lib/gitlab/email/handler/create_issue_handler.rb

55 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'gitlab/email/handler/base_handler'
module Gitlab
module Email
module Handler
class CreateIssueHandler < BaseHandler
2017-08-17 22:00:37 +05:30
include ReplyProcessing
attr_reader :project_path, :incoming_email_token
2016-09-13 17:45:13 +05:30
def initialize(mail, mail_key)
super(mail, mail_key)
2017-08-17 22:00:37 +05:30
@project_path, @incoming_email_token =
2016-09-13 17:45:13 +05:30
mail_key && mail_key.split('+', 2)
end
def can_handle?
2018-10-15 14:42:47 +05:30
!incoming_email_token.nil? && !incoming_email_token.include?("+") && !mail_key.include?(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX)
2016-09-13 17:45:13 +05:30
end
def execute
raise ProjectNotFound unless project
validate_permission!(:create_issue)
verify_record!(
record: create_issue,
invalid_exception: InvalidIssueError,
record_name: 'issue')
end
def author
2017-08-17 22:00:37 +05:30
@author ||= User.find_by(incoming_email_token: incoming_email_token)
2016-09-13 17:45:13 +05:30
end
def project
2017-08-17 22:00:37 +05:30
@project ||= Project.find_by_full_path(project_path)
end
2016-09-13 17:45:13 +05:30
private
def create_issue
Issues::CreateService.new(
project,
author,
title: mail.subject,
2018-11-08 19:23:39 +05:30
description: message_including_reply
2016-09-13 17:45:13 +05:30
).execute
end
end
end
end
end