Commit 401340168c4596a872fd5d94ec9d52b33886f45f
1 parent
82e25518
Exists in
master
and in
4 other branches
bypass gitolite update hook, and set an GL_USER variable.
Showing
3 changed files
with
17 additions
and
10 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 | ... | ... |