diff options
| author | Sean McGivern <sean@gitlab.com> | 2016-12-09 12:52:26 +0000 |
|---|---|---|
| committer | Sean McGivern <sean@gitlab.com> | 2016-12-12 13:21:42 +0000 |
| commit | fbc213eabdbb76ec846357d980705f5d4f20ecc5 (patch) | |
| tree | fbc84343e0aa947c2a30e2b1040253ba7fbd1852 /lib | |
| parent | 8e370b37e16dc8eebeca264c6c351dc4a4fdab4a (diff) | |
| download | gitlab-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')
| -rw-r--r-- | lib/gitlab_config.rb | 7 | ||||
| -rw-r--r-- | lib/gitlab_custom_hook.rb | 18 |
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/gitlab_config.rb b/lib/gitlab_config.rb index f8a10cf..a51a32c 100644 --- a/lib/gitlab_config.rb +++ b/lib/gitlab_config.rb @@ -19,6 +19,13 @@ class GitlabConfig @config['secret_file'] ||= File.join(ROOT_PATH, '.gitlab_shell_secret') end + # Pass a default value because this is called from a repo's context; in which + # case, the repo's hooks directory should be the default. + # + def custom_hooks_dir(default: nil) + @config['custom_hooks_dir'] || default + end + def gitlab_url (@config['gitlab_url'] ||= "http://localhost:8080").sub(%r{/*$}, '') end 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 |
