summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Hörner <dirker@gmail.com>2016-09-05 12:06:32 +0200
committerSean McGivern <sean@gitlab.com>2016-12-01 11:40:11 +0000
commit0e409ee49b1d68ea949da2d0504f325439ad53b3 (patch)
treef056b1fa4b0d0c936cf027d770b6b7f7672d73a7
parentd05522de85dcdfa91349c0d9fc78bf72931d6a39 (diff)
downloadgitlab-shell-0e409ee49b1d68ea949da2d0504f325439ad53b3.tar.gz
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).
-rw-r--r--.gitignore1
-rwxr-xr-xhooks/post-receive1
-rwxr-xr-xhooks/pre-receive1
-rwxr-xr-xhooks/update1
-rw-r--r--lib/gitlab_custom_hook.rb34
5 files changed, 26 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 62e2cd1..995e19d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ coverage/
.bundle
tags
.bundle/
+custom_hooks
diff --git a/hooks/post-receive b/hooks/post-receive
index 7877306..16a6fa9 100755
--- a/hooks/post-receive
+++ b/hooks/post-receive
@@ -7,6 +7,7 @@ refs = $stdin.read
key_id = ENV.delete('GL_ID')
repo_path = Dir.pwd
+require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_custom_hook'
require_relative '../lib/gitlab_post_receive'
diff --git a/hooks/pre-receive b/hooks/pre-receive
index 1b16fd0..97b9669 100755
--- a/hooks/pre-receive
+++ b/hooks/pre-receive
@@ -8,6 +8,7 @@ key_id = ENV.delete('GL_ID')
protocol = ENV.delete('GL_PROTOCOL')
repo_path = Dir.pwd
+require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_custom_hook'
require_relative '../lib/gitlab_reference_counter'
require_relative '../lib/gitlab_access'
diff --git a/hooks/update b/hooks/update
index 4c2fc08..e569446 100755
--- a/hooks/update
+++ b/hooks/update
@@ -9,6 +9,7 @@ new_value = ARGV[2]
repo_path = Dir.pwd
key_id = ENV.delete('GL_ID')
+require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_custom_hook'
if GitlabCustomHook.new(repo_path, key_id).update(ref_name, old_value, new_value)
diff --git a/lib/gitlab_custom_hook.rb b/lib/gitlab_custom_hook.rb
index 0187e1e..f7ae6de 100644
--- a/lib/gitlab_custom_hook.rb
+++ b/lib/gitlab_custom_hook.rb
@@ -11,28 +11,38 @@ class GitlabCustomHook
end
def pre_receive(changes)
- hook = hook_file('pre-receive', @repo_path)
- return true if hook.nil?
-
- GitlabMetrics.measure("pre-receive-hook") { call_receive_hook(hook, changes) }
+ GitlabMetrics.measure("pre-receive-hook") do
+ find_hooks('pre-receive').all? do |hook|
+ call_receive_hook(hook, changes)
+ end
+ end
end
def post_receive(changes)
- hook = hook_file('post-receive', @repo_path)
- return true if hook.nil?
-
- GitlabMetrics.measure("post-receive-hook") { call_receive_hook(hook, changes) }
+ GitlabMetrics.measure("post-receive-hook") do
+ find_hooks('post-receive').all? do |hook|
+ call_receive_hook(hook, changes)
+ end
+ end
end
def update(ref_name, old_value, new_value)
- hook = hook_file('update', @repo_path)
- return true if hook.nil?
-
- GitlabMetrics.measure("update-hook") { system(vars, hook, ref_name, old_value, new_value) }
+ GitlabMetrics.measure("update-hook") do
+ find_hooks('update').all? do |hook|
+ system(vars, hook, ref_name, old_value, new_value)
+ end
+ end
end
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)
# Prepare the hook subprocess. Attach a pipe to its stdin, and merge
# both its stdout and stderr into our own stdout.