bypass gitolite update hook, and set an GL_USER variable.

This commit is contained in:
Saito 2012-07-02 16:44:45 +08:00
parent 82e2551833
commit 401340168c
3 changed files with 17 additions and 10 deletions

View file

@ -86,12 +86,10 @@ module GitPush
# This method will be called after each post receive # This method will be called after each post receive
# and only if autor_key_id present in gitlab. # and only if user present in gitlab.
# All callbacks for post receive should be placed here # All callbacks for post receive should be placed here
# #
def trigger_post_receive(oldrev, newrev, ref, author_key_id) def trigger_post_receive(oldrev, newrev, ref, user)
user = Key.find_by_identifier(author_key_id).user
# Create push event # Create push event
self.observe_push(oldrev, newrev, ref, user) self.observe_push(oldrev, newrev, ref, user)

View file

@ -1,13 +1,17 @@
class PostReceive class PostReceive
@queue = :post_receive @queue = :post_receive
def self.perform(reponame, oldrev, newrev, ref, author_key_id) def self.perform(reponame, oldrev, newrev, ref, identifier)
project = Project.find_by_path(reponame) project = Project.find_by_path(reponame)
return false if project.nil? return false if project.nil?
# Ignore push from non-gitlab users # Ignore push from non-gitlab users
return false unless Key.find_by_identifier(author_key_id) if /^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/.match(identifier)
return false unless user = User.find_by_email(identifier)
else
return false unless user = Key.find_by_identifier(identifier).try(:user)
end
project.trigger_post_receive(oldrev, newrev, ref, author_key_id) project.trigger_post_receive(oldrev, newrev, ref, user)
end end
end end

View file

@ -7,6 +7,11 @@ module Grack
user = User.find_by_email(email) user = User.find_by_email(email)
return false unless user.try(:valid_password?, password) return false unless user.try(:valid_password?, password)
# Set GL_USER env variable
ENV['GL_USER'] = email
# Pass Gitolite update hook
ENV['GL_BYPASS_UPDATE_HOOK'] = "true"
# Need this patch because the rails mount # Need this patch because the rails mount
@env['PATH_INFO'] = @env['REQUEST_PATH'] @env['PATH_INFO'] = @env['REQUEST_PATH']