diff options
author | Olivier CrĂȘte <olivier.crete@ocrete.ca> | 2018-12-13 14:15:48 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-12-13 14:15:48 +0300 |
commit | a96cd7cb2bd3cfcafc30a349bdd9289f9db055a5 (patch) | |
tree | d76a1149567ab764c31fdc7ee50a033e7f69005c /app/helpers/emails_helper.rb | |
parent | 3821813d1a5f43c1e7dc43347425198b38f1086d (diff) |
Add List-Id to notification emails
Diffstat (limited to 'app/helpers/emails_helper.rb')
-rw-r--r-- | app/helpers/emails_helper.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/helpers/emails_helper.rb b/app/helpers/emails_helper.rb index 2d2e89a2a50..e4c46ceeaa2 100644 --- a/app/helpers/emails_helper.rb +++ b/app/helpers/emails_helper.rb @@ -98,4 +98,29 @@ module EmailsHelper "#{string} on #{Gitlab.config.gitlab.host}" end + + def create_list_id_string(project, list_id_max_length = 255) + project_path_as_domain = project.full_path.downcase + .split('/').reverse.join('/') + .gsub(%r{[^a-z0-9\/]}, '-') + .gsub(%r{\/+}, '.') + .gsub(/(\A\.+|\.+\z)/, '') + + max_domain_length = list_id_max_length - Gitlab.config.gitlab.host.length - project.id.to_s.length - 2 + + if max_domain_length < 3 + return project.id.to_s + "..." + Gitlab.config.gitlab.host + end + + if project_path_as_domain.length > max_domain_length + project_path_as_domain = project_path_as_domain.slice(0, max_domain_length) + + last_dot_index = project_path_as_domain[0..-2].rindex(".") + last_dot_index ||= max_domain_length - 2 + + project_path_as_domain = project_path_as_domain.slice(0, last_dot_index).concat("..") + end + + project.id.to_s + "." + project_path_as_domain + "." + Gitlab.config.gitlab.host + end end |