Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/ruby
diff options
context:
space:
mode:
authorJames Fargher <proglottis@gmail.com>2020-09-17 05:48:00 +0300
committerJames Fargher <proglottis@gmail.com>2020-09-17 05:48:00 +0300
commit974ed277520086b2a9c830fab11a3076234f13a9 (patch)
tree641a44c5fd896aabae6c92d961b65e3822291f07 /ruby
parentbb215faacd87e57e832abb3b6ac30870c7b3a186 (diff)
parentb44de3009cd851681a21565a37d4072474aaf2cd (diff)
Merge branch 'pks-ruby-reftx-hook' into 'master'
hooks: Call reference-transaction hook from Ruby HooksService Closes #3034 See merge request gitlab-org/gitaly!2566
Diffstat (limited to 'ruby')
-rw-r--r--ruby/lib/gitlab/git/hook.rb42
-rw-r--r--ruby/lib/gitlab/git/hooks_service.rb2
2 files changed, 29 insertions, 15 deletions
diff --git a/ruby/lib/gitlab/git/hook.rb b/ruby/lib/gitlab/git/hook.rb
index c391bbf78..4a6ee936f 100644
--- a/ruby/lib/gitlab/git/hook.rb
+++ b/ruby/lib/gitlab/git/hook.rb
@@ -35,6 +35,8 @@ module Gitlab
case name
when "pre-receive", "post-receive"
call_receive_hook(gl_id, gl_username, oldrev, newrev, ref, push_options, transaction)
+ when "reference-transaction"
+ call_reference_transaction_hook(gl_id, gl_username, oldrev, newrev, ref, transaction)
when "update"
call_update_hook(gl_id, gl_username, oldrev, newrev, ref)
end
@@ -43,30 +45,22 @@ module Gitlab
private
- def call_receive_hook(gl_id, gl_username, oldrev, newrev, ref, push_options, transaction)
- changes = [oldrev, newrev, ref].join(" ")
-
+ def call_stdin_hook(args, input, env)
exit_status = false
exit_message = nil
- vars = env_base_vars(gl_id, gl_username)
- vars.merge!(push_options.env_data) if push_options
- vars.merge!(transaction.env_vars) if transaction
-
options = {
chdir: repo_path
}
- Open3.popen3(vars, path, options) do |stdin, stdout, stderr, wait_thr|
+ Open3.popen3(env, path, *args, options) do |stdin, stdout, stderr, wait_thr|
exit_status = true
stdin.sync = true
- # in git, pre- and post- receive hooks may just exit without
- # reading stdin. We catch the exception to avoid a broken pipe
- # warning
+ # in git, hooks may just exit without reading stdin. We catch the
+ # exception to avoid a broken pipe warning
begin
- # inject all the changes as stdin to the hook
- changes.lines do |line|
+ input.lines do |line|
stdin.puts line
end
rescue Errno::EPIPE
@@ -83,6 +77,25 @@ module Gitlab
[exit_status, exit_message]
end
+ def call_receive_hook(gl_id, gl_username, oldrev, newrev, ref, push_options, transaction)
+ changes = [oldrev, newrev, ref].join(" ")
+
+ vars = env_base_vars(gl_id, gl_username)
+ vars.merge!(push_options.env_data) if push_options
+ vars.merge!(transaction.env_vars) if transaction
+
+ call_stdin_hook([], changes, vars)
+ end
+
+ def call_reference_transaction_hook(gl_id, gl_username, oldrev, newrev, ref, transaction)
+ changes = [oldrev, newrev, ref].join(" ")
+
+ vars = env_base_vars(gl_id, gl_username)
+ vars.merge!(transaction.env_vars) if transaction
+
+ call_stdin_hook(["prepared"], changes, vars)
+ end
+
def call_update_hook(gl_id, gl_username, oldrev, newrev, ref)
options = {
chdir: repo_path
@@ -120,7 +133,8 @@ module Gitlab
'GIT_DIR' => repo_path,
'GITALY_REPO' => repository.gitaly_repository.to_json,
'GITALY_SOCKET' => Gitlab.config.gitaly.internal_socket,
- 'GITALY_GO_POSTRECEIVE' => repository.feature_enabled?('go-postreceive-hook').to_s
+ 'GITALY_GO_POSTRECEIVE' => repository.feature_enabled?('go-postreceive-hook').to_s,
+ 'GITALY_REFERENCE_TRANSACTION_HOOK' => repository.feature_enabled?('reference-transaction-hook').to_s
}
end
end
diff --git a/ruby/lib/gitlab/git/hooks_service.rb b/ruby/lib/gitlab/git/hooks_service.rb
index 5ad8e43b7..67ac4c3fb 100644
--- a/ruby/lib/gitlab/git/hooks_service.rb
+++ b/ruby/lib/gitlab/git/hooks_service.rb
@@ -13,7 +13,7 @@ module Gitlab
@push_options = push_options
@transaction = transaction
- %w[pre-receive update].each do |hook_name|
+ %w[pre-receive update reference-transaction].each do |hook_name|
status, message = run_hook(hook_name)
raise PreReceiveError, message unless status