Commit 15a03e1d871c9d74508af74abd6705a1c27bb6c7

Authored by Dmitriy Zaporozhets
2 parents f464d4c9 40134016

Merge pull request #1023 from SaitoWu/feature/https

Feature/https
app/roles/git_push.rb
@@ -21,7 +21,7 @@ module GitPush @@ -21,7 +21,7 @@ module GitPush
21 21
22 # Close merge requests 22 # Close merge requests
23 mrs = self.merge_requests.opened.where(:target_branch => branch_name).all 23 mrs = self.merge_requests.opened.where(:target_branch => branch_name).all
24 - mrs = mrs.select(&:last_commit).select { |mr| c_ids.include?(mr.last_commit.id) } 24 + mrs = mrs.select(&:last_commit).select { |mr| c_ids.include?(mr.last_commit.id) }
25 mrs.each { |merge_request| merge_request.merge!(user.id) } 25 mrs.each { |merge_request| merge_request.merge!(user.id) }
26 26
27 true 27 true
@@ -65,7 +65,7 @@ module GitPush @@ -65,7 +65,7 @@ module GitPush
65 total_commits_count: push_commits_count 65 total_commits_count: push_commits_count
66 } 66 }
67 67
68 - # For perfomance purposes maximum 20 latest commits 68 + # For perfomance purposes maximum 20 latest commits
69 # will be passed as post receive hook data. 69 # will be passed as post receive hook data.
70 # 70 #
71 push_commits_limited.each do |commit| 71 push_commits_limited.each do |commit|
@@ -86,16 +86,14 @@ module GitPush @@ -86,16 +86,14 @@ module GitPush
86 86
87 87
88 # This method will be called after each post receive 88 # This method will be called after each post receive
89 - # and only if autor_key_id present in gitlab. 89 + # and only if user present in gitlab.
90 # All callbacks for post receive should be placed here 90 # All callbacks for post receive should be placed here
91 # 91 #
92 - def trigger_post_receive(oldrev, newrev, ref, author_key_id)  
93 - user = Key.find_by_identifier(author_key_id).user  
94 - 92 + def trigger_post_receive(oldrev, newrev, ref, user)
95 # Create push event 93 # Create push event
96 self.observe_push(oldrev, newrev, ref, user) 94 self.observe_push(oldrev, newrev, ref, user)
97 95
98 - # Close merged MR 96 + # Close merged MR
99 self.update_merge_requests(oldrev, newrev, ref, user) 97 self.update_merge_requests(oldrev, newrev, ref, user)
100 98
101 # Execute web hooks 99 # Execute web hooks
app/workers/post_receive.rb
1 class PostReceive 1 class PostReceive
2 @queue = :post_receive 2 @queue = :post_receive
3 3
4 - def self.perform(reponame, oldrev, newrev, ref, author_key_id) 4 + def self.perform(reponame, oldrev, newrev, ref, identifier)
5 project = Project.find_by_path(reponame) 5 project = Project.find_by_path(reponame)
6 return false if project.nil? 6 return false if project.nil?
7 7
8 # Ignore push from non-gitlab users 8 # Ignore push from non-gitlab users
9 - return false unless Key.find_by_identifier(author_key_id) 9 + if /^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/.match(identifier)
  10 + return false unless user = User.find_by_email(identifier)
  11 + else
  12 + return false unless user = Key.find_by_identifier(identifier).try(:user)
  13 + end
10 14
11 - project.trigger_post_receive(oldrev, newrev, ref, author_key_id) 15 + project.trigger_post_receive(oldrev, newrev, ref, user)
12 end 16 end
13 end 17 end
config/initializers/grack_auth.rb
@@ -7,6 +7,11 @@ module Grack @@ -7,6 +7,11 @@ module Grack
7 user = User.find_by_email(email) 7 user = User.find_by_email(email)
8 return false unless user.try(:valid_password?, password) 8 return false unless user.try(:valid_password?, password)
9 9
  10 + # Set GL_USER env variable
  11 + ENV['GL_USER'] = email
  12 + # Pass Gitolite update hook
  13 + ENV['GL_BYPASS_UPDATE_HOOK'] = "true"
  14 +
10 # Need this patch because the rails mount 15 # Need this patch because the rails mount
11 @env['PATH_INFO'] = @env['REQUEST_PATH'] 16 @env['PATH_INFO'] = @env['REQUEST_PATH']
12 17
config/routes.rb
@@ -18,7 +18,7 @@ Gitlab::Application.routes.draw do @@ -18,7 +18,7 @@ Gitlab::Application.routes.draw do
18 project_root: GIT_HOST['base_path'], 18 project_root: GIT_HOST['base_path'],
19 upload_pack: GIT_HOST['upload_pack'], 19 upload_pack: GIT_HOST['upload_pack'],
20 receive_pack: GIT_HOST['receive_pack'] 20 receive_pack: GIT_HOST['receive_pack']
21 - }), at: '/:path', constraints: { path: /[\w-]+.git*/ } 21 + }), at: '/:path', constraints: { path: /[\w-]+\.git/ }
22 22
23 # 23 #
24 # Help 24 # Help