Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-08-22 15:18:09 +0300
committerJacob Vosmaer <jacob@gitlab.com>2017-08-23 11:45:20 +0300
commitdc7c6bede27abd4507072276ef23b40a74ee297a (patch)
tree3337af56f28df2cbd0f33a369b0a42fa3cec2c95 /lib/gitlab/git/hooks_service.rb
parent65f83941c39c14c2af9da5064393545ea2f7b3e5 (diff)
Move GitHooksService to Gitlab::Git
Diffstat (limited to 'lib/gitlab/git/hooks_service.rb')
-rw-r--r--lib/gitlab/git/hooks_service.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/gitlab/git/hooks_service.rb b/lib/gitlab/git/hooks_service.rb
new file mode 100644
index 00000000000..1da92fcc0e2
--- /dev/null
+++ b/lib/gitlab/git/hooks_service.rb
@@ -0,0 +1,37 @@
+module Gitlab
+ module Git
+ class HooksService
+ PreReceiveError = Class.new(StandardError)
+
+ attr_accessor :oldrev, :newrev, :ref
+
+ def execute(committer, repository, oldrev, newrev, ref)
+ @repository = repository
+ @gl_id = committer.gl_id
+ @oldrev = oldrev
+ @newrev = newrev
+ @ref = ref
+
+ %w(pre-receive update).each do |hook_name|
+ status, message = run_hook(hook_name)
+
+ unless status
+ raise PreReceiveError, message
+ end
+ end
+
+ yield(self).tap do
+ run_hook('post-receive')
+ end
+ end
+
+ private
+
+ def run_hook(name)
+ hook = Gitlab::Git::Hook.new(name, @repository)
+ hook.trigger(@gl_id, oldrev, newrev, ref)
+ end
+ end
+ end
+end
+