summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Turner <dturner@twosigma.com>2017-08-02 14:14:50 -0400
committerDavid Turner <novalis@novalis.org>2017-09-29 18:12:03 -0400
commitdbcf48af8b21c0f1e54b73ea421911028081e1c1 (patch)
tree079829ac40d22cd745749d8cfaf5c56c21c4112d /lib
parent999b7e553b1e1e04c2be4289b94557813f140cfe (diff)
downloadgitlab-ce-dbcf48af8b21c0f1e54b73ea421911028081e1c1.tar.gz
Add username as GL_USERNAME in hooks (http)
When calling pre-receive, post-receive, and update hooks, add the GitLab username as the GL_USERNAME environment variable. This patch only handles cases where pushes are over http, or via the web interface. Later, we will address the ssh case.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/hook.rb18
-rw-r--r--lib/gitlab/git/hooks_service.rb15
-rw-r--r--lib/gitlab/git/user.rb9
3 files changed, 25 insertions, 17 deletions
diff --git a/lib/gitlab/git/hook.rb b/lib/gitlab/git/hook.rb
index 208e4bbaf60..8ccb3e64636 100644
--- a/lib/gitlab/git/hook.rb
+++ b/lib/gitlab/git/hook.rb
@@ -22,22 +22,22 @@ module Gitlab
File.exist?(path)
end
- def trigger(gl_id, oldrev, newrev, ref)
+ def trigger(gl_id, gl_username, oldrev, newrev, ref)
return [true, nil] unless exists?
Bundler.with_clean_env do
case name
when "pre-receive", "post-receive"
- call_receive_hook(gl_id, oldrev, newrev, ref)
+ call_receive_hook(gl_id, gl_username, oldrev, newrev, ref)
when "update"
- call_update_hook(gl_id, oldrev, newrev, ref)
+ call_update_hook(gl_id, gl_username, oldrev, newrev, ref)
end
end
end
private
- def call_receive_hook(gl_id, oldrev, newrev, ref)
+ def call_receive_hook(gl_id, gl_username, oldrev, newrev, ref)
changes = [oldrev, newrev, ref].join(" ")
exit_status = false
@@ -45,6 +45,7 @@ module Gitlab
vars = {
'GL_ID' => gl_id,
+ 'GL_USERNAME' => gl_username,
'PWD' => repo_path,
'GL_PROTOCOL' => GL_PROTOCOL,
'GL_REPOSITORY' => repository.gl_repository
@@ -80,9 +81,14 @@ module Gitlab
[exit_status, exit_message]
end
- def call_update_hook(gl_id, oldrev, newrev, ref)
+ def call_update_hook(gl_id, gl_username, oldrev, newrev, ref)
Dir.chdir(repo_path) do
- stdout, stderr, status = Open3.capture3({ 'GL_ID' => gl_id }, path, ref, oldrev, newrev)
+ stdout, stderr, status = Open3.capture3(
+ {
+ 'GL_ID' => gl_id,
+ 'GL_USERNAME' => gl_username
+ },
+ path, ref, oldrev, newrev)
[status.success?, (stderr.presence || stdout).gsub(/\R/, "<br>").html_safe]
end
end
diff --git a/lib/gitlab/git/hooks_service.rb b/lib/gitlab/git/hooks_service.rb
index ea8a87a1290..c327e9b1616 100644
--- a/lib/gitlab/git/hooks_service.rb
+++ b/lib/gitlab/git/hooks_service.rb
@@ -5,12 +5,13 @@ module Gitlab
attr_accessor :oldrev, :newrev, :ref
- def execute(committer, repository, oldrev, newrev, ref)
- @repository = repository
- @gl_id = committer.gl_id
- @oldrev = oldrev
- @newrev = newrev
- @ref = ref
+ def execute(pusher, repository, oldrev, newrev, ref)
+ @repository = repository
+ @gl_id = pusher.gl_id
+ @gl_username = pusher.name
+ @oldrev = oldrev
+ @newrev = newrev
+ @ref = ref
%w(pre-receive update).each do |hook_name|
status, message = run_hook(hook_name)
@@ -29,7 +30,7 @@ module Gitlab
def run_hook(name)
hook = Gitlab::Git::Hook.new(name, @repository)
- hook.trigger(@gl_id, oldrev, newrev, ref)
+ hook.trigger(@gl_id, @gl_username, oldrev, newrev, ref)
end
end
end
diff --git a/lib/gitlab/git/user.rb b/lib/gitlab/git/user.rb
index e142992f324..cb1af5f3b7c 100644
--- a/lib/gitlab/git/user.rb
+++ b/lib/gitlab/git/user.rb
@@ -1,20 +1,21 @@
module Gitlab
module Git
class User
- attr_reader :name, :email, :gl_id
+ attr_reader :username, :name, :email, :gl_id
def self.from_gitlab(gitlab_user)
- new(gitlab_user.name, gitlab_user.email, Gitlab::GlId.gl_id(gitlab_user))
+ new(gitlab_user.username, gitlab_user.name, gitlab_user.email, Gitlab::GlId.gl_id(gitlab_user))
end
- def initialize(name, email, gl_id)
+ def initialize(username, name, email, gl_id)
+ @username = username
@name = name
@email = email
@gl_id = gl_id
end
def ==(other)
- [name, email, gl_id] == [other.name, other.email, other.gl_id]
+ [username, name, email, gl_id] == [other.username, other.name, other.email, other.gl_id]
end
end
end