summaryrefslogtreecommitdiff
path: root/lib/gitlab_custom_hook.rb
diff options
context:
space:
mode:
authorDrew Blessing <drew.blessing@me.com>2014-10-29 22:21:10 -0500
committerDrew Blessing <drew.blessing@me.com>2014-11-05 15:16:43 -0600
commit3ef7cdf9f94035da5640a585b8c49b0693af2090 (patch)
tree5ad3dbaa118504d185071a5f4e36f8a8cbc3e3dd /lib/gitlab_custom_hook.rb
parent00b3d2cb7095af3859734c88a7797182e598f047 (diff)
downloadgitlab-shell-3ef7cdf9f94035da5640a585b8c49b0693af2090.tar.gz
Support for custom hooks
Diffstat (limited to 'lib/gitlab_custom_hook.rb')
-rw-r--r--lib/gitlab_custom_hook.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/gitlab_custom_hook.rb b/lib/gitlab_custom_hook.rb
new file mode 100644
index 0000000..d6fa83d
--- /dev/null
+++ b/lib/gitlab_custom_hook.rb
@@ -0,0 +1,42 @@
+class GitlabCustomHook
+ def pre_receive(refs, repo_path)
+ if receive('pre-receive', refs, repo_path)
+ return true
+ else
+ # reset GL_ID env since we stop git push here
+ ENV['GL_ID'] = nil
+ return false
+ end
+ end
+
+ def post_receive(refs, repo_path)
+ receive('post-receive', refs, repo_path)
+ end
+
+ def update(ref_name, old_value, new_value, repo_path)
+ hook = hook_file('update', repo_path)
+ return true if hook.nil?
+ system(*hook, ref_name, old_value, new_value) ? true : false
+ end
+
+ private
+
+ def receive(type, refs, repo_path)
+ unless type == 'pre-receive' || type == 'post-receive'
+ puts 'GitLab: An unexpected error occurred ' \
+ '(invalid pre/post-receive hook type)'
+ return false
+ end
+
+ hook = hook_file(type, repo_path)
+ return true if hook.nil?
+ cmd = "#{hook} #{refs}"
+ system(*cmd) ? true : false
+ end
+
+ def hook_file(hook_type, repo_path)
+ hook_path = File.join(repo_path.strip, 'custom_hooks')
+ hook_file = "#{hook_path}/#{hook_type}"
+ hook_file if File.exist?(hook_file)
+ end
+end