Commit 15a03e1d871c9d74508af74abd6705a1c27bb6c7
Exists in
master
and in
4 other branches
Merge pull request #1023 from SaitoWu/feature/https
Feature/https
Showing
4 changed files
with
18 additions
and
11 deletions
Show diff stats
app/roles/git_push.rb
... | ... | @@ -21,7 +21,7 @@ module GitPush |
21 | 21 | |
22 | 22 | # Close merge requests |
23 | 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 | 25 | mrs.each { |merge_request| merge_request.merge!(user.id) } |
26 | 26 | |
27 | 27 | true |
... | ... | @@ -65,7 +65,7 @@ module GitPush |
65 | 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 | 69 | # will be passed as post receive hook data. |
70 | 70 | # |
71 | 71 | push_commits_limited.each do |commit| |
... | ... | @@ -86,16 +86,14 @@ module GitPush |
86 | 86 | |
87 | 87 | |
88 | 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 | 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 | 93 | # Create push event |
96 | 94 | self.observe_push(oldrev, newrev, ref, user) |
97 | 95 | |
98 | - # Close merged MR | |
96 | + # Close merged MR | |
99 | 97 | self.update_merge_requests(oldrev, newrev, ref, user) |
100 | 98 | |
101 | 99 | # Execute web hooks | ... | ... |
app/workers/post_receive.rb
1 | 1 | class PostReceive |
2 | 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 | 5 | project = Project.find_by_path(reponame) |
6 | 6 | return false if project.nil? |
7 | 7 | |
8 | 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 | 16 | end |
13 | 17 | end | ... | ... |
config/initializers/grack_auth.rb
... | ... | @@ -7,6 +7,11 @@ module Grack |
7 | 7 | user = User.find_by_email(email) |
8 | 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 | 15 | # Need this patch because the rails mount |
11 | 16 | @env['PATH_INFO'] = @env['REQUEST_PATH'] |
12 | 17 | ... | ... |
config/routes.rb
... | ... | @@ -18,7 +18,7 @@ Gitlab::Application.routes.draw do |
18 | 18 | project_root: GIT_HOST['base_path'], |
19 | 19 | upload_pack: GIT_HOST['upload_pack'], |
20 | 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 | 24 | # Help | ... | ... |