diff options
| author | Rémy Coutable <remy@rymai.me> | 2016-12-12 15:09:20 +0000 |
|---|---|---|
| committer | Rémy Coutable <remy@rymai.me> | 2016-12-12 15:09:20 +0000 |
| commit | 92dad7c1855666cb0755ee1f9f6f1910c903fb92 (patch) | |
| tree | 39ee847a871636e0f71e25ecaf6c50799de31df0 /lib/gitlab_custom_hook.rb | |
| parent | 8e370b37e16dc8eebeca264c6c351dc4a4fdab4a (diff) | |
| parent | bf21f6eeef482c71a5ff2b3d26da048ac236b075 (diff) | |
| download | gitlab-shell-4.1.0.tar.gz | |
Merge branch 'make-custom-hook-dir-configurable' into 'master'
v4.1.0
Make custom hook dir configurable
Add a new configuration option, custom_hook_dir. When this is set, we
will look for global custom hooks in: `<custom_hook_dir>/{pre-receive,update,post-receive}.d/*`
When this is not set, default to `<ROOT_PATH>/hooks`.
Relates to https://gitlab.com/gitlab-org/omnibus-gitlab/issues/1754 and
gitlab-org/gitlab-ce!8040.
See merge request !113
Diffstat (limited to 'lib/gitlab_custom_hook.rb')
| -rw-r--r-- | lib/gitlab_custom_hook.rb | 18 |
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 |
