Commit 0e409ee4 authored by Dirk Hörner's avatar Dirk Hörner Committed by Sean McGivern

custom_hook: add support for global custom hooks

This commit adds the option of having another set of global custom hooks
along with the already supported repository local custom hooks.

The repository local custom hook is executed first (if available). If
successful, execution continues with the global custom hook (if available).
This way, local custom hooks get priority over global custom hooks.

Global custom hooks can be enabled by placing an executable file into the
"custom_hooks" directory within gitlab-shell (create if it does not exist,
yet).
parent d05522de
...@@ -8,3 +8,4 @@ coverage/ ...@@ -8,3 +8,4 @@ coverage/
.bundle .bundle
tags tags
.bundle/ .bundle/
custom_hooks
...@@ -7,6 +7,7 @@ refs = $stdin.read ...@@ -7,6 +7,7 @@ refs = $stdin.read
key_id = ENV.delete('GL_ID') key_id = ENV.delete('GL_ID')
repo_path = Dir.pwd repo_path = Dir.pwd
require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_custom_hook' require_relative '../lib/gitlab_custom_hook'
require_relative '../lib/gitlab_post_receive' require_relative '../lib/gitlab_post_receive'
......
...@@ -8,6 +8,7 @@ key_id = ENV.delete('GL_ID') ...@@ -8,6 +8,7 @@ key_id = ENV.delete('GL_ID')
protocol = ENV.delete('GL_PROTOCOL') protocol = ENV.delete('GL_PROTOCOL')
repo_path = Dir.pwd repo_path = Dir.pwd
require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_custom_hook' require_relative '../lib/gitlab_custom_hook'
require_relative '../lib/gitlab_reference_counter' require_relative '../lib/gitlab_reference_counter'
require_relative '../lib/gitlab_access' require_relative '../lib/gitlab_access'
......
...@@ -9,6 +9,7 @@ new_value = ARGV[2] ...@@ -9,6 +9,7 @@ new_value = ARGV[2]
repo_path = Dir.pwd repo_path = Dir.pwd
key_id = ENV.delete('GL_ID') key_id = ENV.delete('GL_ID')
require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_custom_hook' require_relative '../lib/gitlab_custom_hook'
if GitlabCustomHook.new(repo_path, key_id).update(ref_name, old_value, new_value) if GitlabCustomHook.new(repo_path, key_id).update(ref_name, old_value, new_value)
......
...@@ -11,28 +11,38 @@ class GitlabCustomHook ...@@ -11,28 +11,38 @@ class GitlabCustomHook
end end
def pre_receive(changes) def pre_receive(changes)
hook = hook_file('pre-receive', @repo_path) GitlabMetrics.measure("pre-receive-hook") do
return true if hook.nil? find_hooks('pre-receive').all? do |hook|
call_receive_hook(hook, changes)
GitlabMetrics.measure("pre-receive-hook") { call_receive_hook(hook, changes) } end
end
end end
def post_receive(changes) def post_receive(changes)
hook = hook_file('post-receive', @repo_path) GitlabMetrics.measure("post-receive-hook") do
return true if hook.nil? find_hooks('post-receive').all? do |hook|
call_receive_hook(hook, changes)
GitlabMetrics.measure("post-receive-hook") { call_receive_hook(hook, changes) } end
end
end end
def update(ref_name, old_value, new_value) def update(ref_name, old_value, new_value)
hook = hook_file('update', @repo_path) GitlabMetrics.measure("update-hook") do
return true if hook.nil? find_hooks('update').all? do |hook|
system(vars, hook, ref_name, old_value, new_value)
GitlabMetrics.measure("update-hook") { system(vars, hook, ref_name, old_value, new_value) } end
end
end end
private private
def find_hooks(hook_name)
[
hook_file(hook_name, @repo_path),
hook_file(hook_name, ROOT_PATH)
].compact
end
def call_receive_hook(hook, changes) def call_receive_hook(hook, changes)
# Prepare the hook subprocess. Attach a pipe to its stdin, and merge # Prepare the hook subprocess. Attach a pipe to its stdin, and merge
# both its stdout and stderr into our own stdout. # both its stdout and stderr into our own stdout.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment