diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /lib/gitlab/email | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'lib/gitlab/email')
-rw-r--r-- | lib/gitlab/email/common.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/email/handler/create_issue_handler.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/email/handler/service_desk_handler.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/email/html_parser.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/email/html_to_markdown_parser.rb | 29 | ||||
-rw-r--r-- | lib/gitlab/email/message/in_product_marketing/create.rb | 8 |
6 files changed, 44 insertions, 10 deletions
diff --git a/lib/gitlab/email/common.rb b/lib/gitlab/email/common.rb index afee8d9cd3d..01316995c4d 100644 --- a/lib/gitlab/email/common.rb +++ b/lib/gitlab/email/common.rb @@ -54,6 +54,10 @@ module Gitlab # It's looking for each <...> references.scan(/(?!<)[^<>]+(?=>)/) end + + def encrypted_secrets + Settings.encrypted(config.encrypted_secret_file) + end end end end diff --git a/lib/gitlab/email/handler/create_issue_handler.rb b/lib/gitlab/email/handler/create_issue_handler.rb index e21a88c4e0d..c325112b673 100644 --- a/lib/gitlab/email/handler/create_issue_handler.rb +++ b/lib/gitlab/email/handler/create_issue_handler.rb @@ -62,7 +62,7 @@ module Gitlab def create_issue ::Issues::CreateService.new( - project: project, + container: project, current_user: author, params: { title: mail.subject, diff --git a/lib/gitlab/email/handler/service_desk_handler.rb b/lib/gitlab/email/handler/service_desk_handler.rb index 06365296a76..076ba42daac 100644 --- a/lib/gitlab/email/handler/service_desk_handler.rb +++ b/lib/gitlab/email/handler/service_desk_handler.rb @@ -92,7 +92,7 @@ module Gitlab def create_issue! result = ::Issues::CreateService.new( - project: project, + container: project, current_user: User.support_bot, params: { title: mail.subject, diff --git a/lib/gitlab/email/html_parser.rb b/lib/gitlab/email/html_parser.rb index 27ba5d2a314..10dbedbb464 100644 --- a/lib/gitlab/email/html_parser.rb +++ b/lib/gitlab/email/html_parser.rb @@ -18,9 +18,6 @@ module Gitlab end def filter_replies! - document.xpath('//blockquote').each(&:remove) - document.xpath('//table').each(&:remove) - # bogus links with no href are sometimes added by outlook, # and can result in Html2Text adding extra square brackets # to the text, so we unwrap them here. @@ -37,7 +34,11 @@ module Gitlab end def filtered_text - @filtered_text ||= Html2Text.convert(filtered_html) + @filtered_text ||= if Feature.enabled?(:service_desk_html_to_text_email_handler) + ::Gitlab::Email::HtmlToMarkdownParser.convert(filtered_html) + else + Html2Text.convert(filtered_html) + end end end end diff --git a/lib/gitlab/email/html_to_markdown_parser.rb b/lib/gitlab/email/html_to_markdown_parser.rb new file mode 100644 index 00000000000..42dd012308b --- /dev/null +++ b/lib/gitlab/email/html_to_markdown_parser.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'nokogiri' + +module Gitlab + module Email + class HtmlToMarkdownParser < Html2Text + ADDITIONAL_TAGS = %w[em strong img details].freeze + IMG_ATTRS = %w[alt src].freeze + + def self.convert(html) + html = fix_newlines(replace_entities(html)) + doc = Nokogiri::HTML(html) + + HtmlToMarkdownParser.new(doc).convert + end + + def iterate_over(node) + return super unless ADDITIONAL_TAGS.include?(node.name) + + if node.name == 'img' + node.keys.each { |key| node.remove_attribute(key) unless IMG_ATTRS.include?(key) } # rubocop:disable Style/HashEachMethods + end + + Kramdown::Document.new(node.to_html, input: 'html').to_commonmark + end + end + end +end diff --git a/lib/gitlab/email/message/in_product_marketing/create.rb b/lib/gitlab/email/message/in_product_marketing/create.rb index 6b01c83b8e7..68f9a9a21c9 100644 --- a/lib/gitlab/email/message/in_product_marketing/create.rb +++ b/lib/gitlab/email/message/in_product_marketing/create.rb @@ -68,7 +68,7 @@ module Gitlab private def project_link - link(s_('InProductMarketing|create a project'), help_page_url('gitlab-basics/create-project')) + link(s_('InProductMarketing|create a project'), help_page_url('user/project/index')) end def repo_link @@ -76,7 +76,7 @@ module Gitlab end def github_link - link(s_('InProductMarketing|GitHub Enterprise projects to GitLab'), help_page_url('integration/github')) + link(s_('InProductMarketing|GitHub Enterprise projects to GitLab'), help_page_url('user/project/import/github')) end def bitbucket_link @@ -84,11 +84,11 @@ module Gitlab end def mirroring_link - link(s_('InProductMarketing|repository mirroring'), help_page_url('user/project/repository/repository_mirroring')) + link(s_('InProductMarketing|repository mirroring'), help_page_url('user/project/repository/mirror/index')) end def basics_link - link(s_('InProductMarketing|Git basics'), help_page_url('gitlab-basics/index')) + link(s_('InProductMarketing|Git basics'), help_page_url('topics/git/index')) end def import_link |