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:
authorBrett Walker <bwalker@gitlab.com>2018-12-14 21:37:03 +0300
committerBrett Walker <bwalker@gitlab.com>2019-01-03 23:37:35 +0300
commit2e514314031f1722db45e2440eb1c7df105218dd (patch)
tree95f47e8c3233d1680543958e90e2629b32f62b9d /lib/gitlab/email/handler/create_issue_handler.rb
parent34dd6196e31b248dc614edd531105ee6b6551060 (diff)
Use new issue email address format
We now use `-issue` in order to support catch all email addresses
Diffstat (limited to 'lib/gitlab/email/handler/create_issue_handler.rb')
-rw-r--r--lib/gitlab/email/handler/create_issue_handler.rb29
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/gitlab/email/handler/create_issue_handler.rb b/lib/gitlab/email/handler/create_issue_handler.rb
index 69982efbbe6..7e5fa5f5cd2 100644
--- a/lib/gitlab/email/handler/create_issue_handler.rb
+++ b/lib/gitlab/email/handler/create_issue_handler.rb
@@ -2,21 +2,30 @@
require 'gitlab/email/handler/base_handler'
+# handles issue creation emails with these formats:
+# incoming+gitlab-org-gitlab-ce-20-Author_Token12345678-issue@incoming.gitlab.com
+# incoming+gitlab-org/gitlab-ce+Author_Token12345678@incoming.gitlab.com (legacy)
module Gitlab
module Email
module Handler
class CreateIssueHandler < BaseHandler
include ReplyProcessing
- attr_reader :project_path, :incoming_email_token
+
+ HANDLER_REGEX = /\A.+-(?<project_id>.+)-(?<incoming_email_token>.+)-issue\z/.freeze
+ HANDLER_REGEX_LEGACY = /\A(?<project_path>[^\+]*)\+(?<incoming_email_token>.*)\z/.freeze
def initialize(mail, mail_key)
super(mail, mail_key)
- @project_path, @incoming_email_token =
- mail_key && mail_key.split('+', 2)
+
+ if matched = HANDLER_REGEX.match(mail_key.to_s)
+ @project_id, @incoming_email_token = matched.captures
+ elsif matched = HANDLER_REGEX_LEGACY.match(mail_key.to_s)
+ @project_path, @incoming_email_token = matched.captures
+ end
end
def can_handle?
- !incoming_email_token.nil? && !incoming_email_token.include?("+") && !mail_key.include?(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX)
+ incoming_email_token && (project_id || can_handle_legacy_format?)
end
def execute
@@ -37,11 +46,17 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord
def project
- @project ||= Project.find_by_full_path(project_path)
+ @project ||= if project_id
+ Project.find_by_id(project_id)
+ else
+ Project.find_by_full_path(project_path)
+ end
end
private
+ attr_reader :project_id, :project_path, :incoming_email_token
+
def create_issue
Issues::CreateService.new(
project,
@@ -50,6 +65,10 @@ module Gitlab
description: message_including_reply
).execute
end
+
+ def can_handle_legacy_format?
+ project_path && !incoming_email_token.include?('+') && !mail_key.include?(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX_LEGACY)
+ end
end
end
end