Commit b698094d authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Update post-receive worker to use correct identifier

parent a5947e44dd87
......@@ -21,14 +21,18 @@ def perform(repo_path, oldrev, newrev, ref, identifier)
return false
end
# Ignore push from non-gitlab users
user = if identifier.nil?
raise identifier.inspect
user = if identifier.blank?
# Local push from gitlab
email = project.repository.commit(newrev).author.email rescue nil
User.find_by_email(email) if email
elsif /^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/.match(identifier)
User.find_by_email(identifier)
elsif identifier =~ /key/
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
......
......@@ -7,9 +7,6 @@ def call(env)
@request = Rack::Request.new(env)
@auth = Request.new(env)
# Pass Gitolite update hook
ENV['GL_BYPASS_UPDATE_HOOK'] = "true"
# Need this patch due to the rails mount
@env['PATH_INFO'] = @request.path
@env['SCRIPT_NAME'] = ""
......@@ -35,8 +32,8 @@ def valid?
self.user = User.find_by_email(login) || User.find_by_username(login)
return false unless user.try(:valid_password?, password)
# Set GL_USER env variable
ENV['GL_USER'] = user.email
# Set GL_ID env variable
ENV['GL_ID'] = "user-#{user.id}"
end
# Git upload and receive
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment