diff options
author | Brett Walker <bwalker@gitlab.com> | 2018-12-28 21:53:39 +0300 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2019-01-03 23:37:35 +0300 |
commit | a4f2de796411236bfda81b7fa281cfa8199c5acf (patch) | |
tree | d1af8211ccae7ea525ca01f06c4993d4710c2771 /lib/gitlab/email/handler/reply_processing.rb | |
parent | 54eb6260e75690ec45802618a7e1b9807f0e7e08 (diff) |
Refactoring and review comments
including verifying the project_slug
Diffstat (limited to 'lib/gitlab/email/handler/reply_processing.rb')
-rw-r--r-- | lib/gitlab/email/handler/reply_processing.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/gitlab/email/handler/reply_processing.rb b/lib/gitlab/email/handler/reply_processing.rb index ff6b2c729b2..76b393f3259 100644 --- a/lib/gitlab/email/handler/reply_processing.rb +++ b/lib/gitlab/email/handler/reply_processing.rb @@ -6,13 +6,28 @@ module Gitlab module ReplyProcessing private + HANDLER_ACTION_BASE_REGEX = /(?<project_slug>.+)-(?<project_id>\d+)-(?<incoming_email_token>.+)/.freeze + + attr_reader :project_id, :project_slug, :project_path, :incoming_email_token + def author raise NotImplementedError end + # rubocop:disable Gitlab/ModuleWithInstanceVariables def project - raise NotImplementedError + return @project if instance_variable_defined?(:@project) + + if project_id + @project = Project.find_by_id(project_id) + @project = nil unless valid_project_slug?(@project) + else + @project = Project.find_by_full_path(project_path) + end + + @project end + # rubocop:enable Gitlab/ModuleWithInstanceVariables def message @message ||= process_message @@ -58,6 +73,10 @@ module Gitlab raise invalid_exception, msg end + + def valid_project_slug?(found_project) + project_slug == found_project.full_path_slug + end end end end |