debian-mirror-gitlab/lib/gitlab/private_commit_email.rb

33 lines
767 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
module Gitlab
module PrivateCommitEmail
2019-12-04 20:38:33 +05:30
TOKEN = "_private"
2018-12-13 13:39:08 +05:30
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
2019-02-15 15:39:39 +05:30
def user_ids_for_emails(emails)
2023-05-27 22:25:52 +05:30
emails.filter_map { |email| user_id_for_email(email) }.uniq
2019-02-15 15:39:39 +05:30
end
2018-12-13 13:39:08 +05:30
def for_user(user)
hostname = Gitlab::CurrentSettings.current_application_settings.commit_email_hostname
"#{user.id}-#{user.username}@#{hostname}"
end
end
end
end