diff --git a/app/roles/git_push.rb b/app/roles/git_push.rb index 504aa0b5..d557ce4e 100644 --- a/app/roles/git_push.rb +++ b/app/roles/git_push.rb @@ -21,7 +21,7 @@ module GitPush # Close merge requests mrs = self.merge_requests.opened.where(:target_branch => branch_name).all - mrs = mrs.select(&:last_commit).select { |mr| c_ids.include?(mr.last_commit.id) } + mrs = mrs.select(&:last_commit).select { |mr| c_ids.include?(mr.last_commit.id) } mrs.each { |merge_request| merge_request.merge!(user.id) } true @@ -65,7 +65,7 @@ module GitPush total_commits_count: push_commits_count } - # For perfomance purposes maximum 20 latest commits + # For perfomance purposes maximum 20 latest commits # will be passed as post receive hook data. # push_commits_limited.each do |commit| @@ -86,16 +86,14 @@ module GitPush # 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 # - def trigger_post_receive(oldrev, newrev, ref, author_key_id) - user = Key.find_by_identifier(author_key_id).user - + def trigger_post_receive(oldrev, newrev, ref, user) # Create push event self.observe_push(oldrev, newrev, ref, user) - # Close merged MR + # Close merged MR self.update_merge_requests(oldrev, newrev, ref, user) # Execute web hooks diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb index 0ab9079c..5311ede7 100644 --- a/app/workers/post_receive.rb +++ b/app/workers/post_receive.rb @@ -1,13 +1,17 @@ class PostReceive @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) return false if project.nil? # 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 diff --git a/config/initializers/grack_auth.rb b/config/initializers/grack_auth.rb index b44a01f4..5995b873 100644 --- a/config/initializers/grack_auth.rb +++ b/config/initializers/grack_auth.rb @@ -7,6 +7,11 @@ module Grack user = User.find_by_email(email) 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 @env['PATH_INFO'] = @env['REQUEST_PATH']