gitlab-org--gitlab-foss/lib/gitlab/identifier.rb

24 lines
658 B
Ruby
Raw Normal View History

2013-04-29 06:43:18 +00:00
# Detect user based on identifier like
# key-13 or user-36 or last commit
module Gitlab
2013-04-29 06:49:25 +00:00
module Identifier
2013-04-29 06:43:18 +00:00
def identify(identifier, project, newrev)
if identifier.blank?
# Local push from gitlab
2015-04-21 13:13:40 +00:00
email = project.commit(newrev).author_email rescue nil
2014-01-19 18:55:59 +00:00
User.find_by(email: email) if email
2013-04-29 06:43:18 +00:00
elsif identifier =~ /\Auser-\d+\Z/
# git push over http
user_id = identifier.gsub("user-", "")
2014-01-19 18:55:59 +00:00
User.find_by(id: user_id)
2013-04-29 06:43:18 +00:00
elsif identifier =~ /\Akey-\d+\Z/
# git push over ssh
key_id = identifier.gsub("key-", "")
2014-01-19 18:55:59 +00:00
Key.find_by(id: key_id).try(:user)
2013-04-29 06:43:18 +00:00
end
end
end
end