summaryrefslogtreecommitdiff
path: root/lib/gitlab_custom_hook.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2016-12-09 12:52:26 +0000
committerSean McGivern <sean@gitlab.com>2016-12-12 13:21:42 +0000
commitfbc213eabdbb76ec846357d980705f5d4f20ecc5 (patch)
treefbc84343e0aa947c2a30e2b1040253ba7fbd1852 /lib/gitlab_custom_hook.rb
parent8e370b37e16dc8eebeca264c6c351dc4a4fdab4a (diff)
downloadgitlab-shell-fbc213eabdbb76ec846357d980705f5d4f20ecc5.tar.gz
Make custom hooks dir configurable
Add a new configuration option, custom_hooks_dir. When this is set, we will look for global custom hooks in: <custom_hooks_dir>/{pre-receive,update,post-receive}.d/* When this is not set, default to <REPO_PATH>/hooks.
Diffstat (limited to 'lib/gitlab_custom_hook.rb')
-rw-r--r--lib/gitlab_custom_hook.rb18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/gitlab_custom_hook.rb b/lib/gitlab_custom_hook.rb
index a48ad12..b151e29 100644
--- a/lib/gitlab_custom_hook.rb
+++ b/lib/gitlab_custom_hook.rb
@@ -3,11 +3,12 @@ require_relative 'gitlab_init'
require_relative 'gitlab_metrics'
class GitlabCustomHook
- attr_reader :vars
+ attr_reader :vars, :config
def initialize(repo_path, key_id)
@repo_path = repo_path
@vars = { 'GL_ID' => key_id }
+ @config = GitlabConfig.new
end
def pre_receive(changes)
@@ -67,16 +68,17 @@ class GitlabCustomHook
hook_files = []
# <repository>.git/custom_hooks/<hook_name>
- hook_file = File.join(@repo_path, 'custom_hooks', hook_name)
- hook_files.push(hook_file) if File.executable?(hook_file)
+ project_custom_hook_file = File.join(@repo_path, 'custom_hooks', hook_name)
+ hook_files.push(project_custom_hook_file) if File.executable?(project_custom_hook_file)
# <repository>.git/custom_hooks/<hook_name>.d/*
- hook_path = File.join(@repo_path, 'custom_hooks', "#{hook_name}.d")
- hook_files += match_hook_files(hook_path)
+ project_custom_hooks_dir = File.join(@repo_path, 'custom_hooks', "#{hook_name}.d")
+ hook_files += match_hook_files(project_custom_hooks_dir)
- # <repository>.git/hooks/<hook_name>.d/*
- hook_path = File.join(@repo_path, 'hooks', "#{hook_name}.d")
- hook_files += match_hook_files(hook_path)
+ # <repository>.git/hooks/<hook_name>.d/* OR <custom_hook_dir>/<hook_name>.d/*
+ global_custom_hooks_parent = config.custom_hooks_dir(default: File.join(@repo_path, 'hooks'))
+ global_custom_hooks_dir = File.join(global_custom_hooks_parent, "#{hook_name}.d")
+ hook_files += match_hook_files(global_custom_hooks_dir)
hook_files
end