summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-11-07 13:52:08 +0000
committerDouwe Maan <douwe@gitlab.com>2018-11-07 13:52:08 +0000
commitad7d0cb2f4395d4abca83acd9b98b17fc73523c0 (patch)
tree06bc505c89da581d43b9a17d7e16f3dba4c64293 /lib
parente60e591fca3dd720c9a8b3e767d7b1b9f4560967 (diff)
parentc239452b47f2819e3ed2fdaf4679737b3e1a456e (diff)
downloadgitlab-ce-ad7d0cb2f4395d4abca83acd9b98b17fc73523c0.tar.gz
Merge branch '43521-keep-personal-emails-private' into 'master'
Adds option to override commit email Closes #43521 See merge request gitlab-org/gitlab-ce!22560
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/private_commit_email.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/gitlab/private_commit_email.rb b/lib/gitlab/private_commit_email.rb
new file mode 100644
index 00000000000..bade2248ccd
--- /dev/null
+++ b/lib/gitlab/private_commit_email.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module PrivateCommitEmail
+ TOKEN = "_private".freeze
+
+ class << self
+ def regex
+ hostname_regexp = Regexp.escape(Gitlab::CurrentSettings.current_application_settings.commit_email_hostname)
+
+ /\A(?<id>([0-9]+))\-([^@]+)@#{hostname_regexp}\z/
+ end
+
+ def user_id_for_email(email)
+ match = email&.match(regex)
+ return unless match
+
+ match[:id].to_i
+ end
+
+ def for_user(user)
+ hostname = Gitlab::CurrentSettings.current_application_settings.commit_email_hostname
+
+ "#{user.id}-#{user.username}@#{hostname}"
+ end
+ end
+ end
+end