diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-11-07 11:00:21 +0000 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-11-07 12:24:14 +0000 |
commit | c239452b47f2819e3ed2fdaf4679737b3e1a456e (patch) | |
tree | bfaee22cd6c0f180faa2a9f83a97375efd804fff /lib/gitlab/private_commit_email.rb | |
parent | c81d4a65a255146619ccf52ece16757c7db622ae (diff) | |
download | gitlab-ce-c239452b47f2819e3ed2fdaf4679737b3e1a456e.tar.gz |
User can keep their commit email private43521-keep-personal-emails-private
The private commit email is automatically generated in the format:
id-username@noreply.HOSTNAME
GitLab instance admins are able to change the HOSTNAME portion,
that defaults to Gitlab's hostname, to whatever they prefer.
Diffstat (limited to 'lib/gitlab/private_commit_email.rb')
-rw-r--r-- | lib/gitlab/private_commit_email.rb | 28 |
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 |