Module: Gitlab::PrivateCommitEmail

Defined in:
lib/gitlab/private_commit_email.rb

Constant Summary collapse

TOKEN =
"_private"

Class Method Summary collapse

Class Method Details

.for_user(user) ⇒ Object


25
26
27
28
29
# File 'lib/gitlab/private_commit_email.rb', line 25

def for_user(user)
  hostname = Gitlab::CurrentSettings.current_application_settings.commit_email_hostname

  "#{user.id}-#{user.username}@#{hostname}"
end

.regexObject


8
9
10
11
12
# File 'lib/gitlab/private_commit_email.rb', line 8

def regex
  hostname_regexp = Regexp.escape(Gitlab::CurrentSettings.current_application_settings.commit_email_hostname)

  /\A(?<id>([0-9]+))\-([^@]+)@#{hostname_regexp}\z/
end

.user_id_for_email(email) ⇒ Object


14
15
16
17
18
19
# File 'lib/gitlab/private_commit_email.rb', line 14

def user_id_for_email(email)
  match = email&.match(regex)
  return unless match

  match[:id].to_i
end

.user_ids_for_emails(emails) ⇒ Object


21
22
23
# File 'lib/gitlab/private_commit_email.rb', line 21

def user_ids_for_emails(emails)
  emails.map { |email| user_id_for_email(email) }.compact.uniq
end