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

24 lines
666 B
Ruby
Raw Normal View History

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