diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2017-08-22 15:18:09 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-08-23 11:45:20 +0300 |
commit | dc7c6bede27abd4507072276ef23b40a74ee297a (patch) | |
tree | 3337af56f28df2cbd0f33a369b0a42fa3cec2c95 /lib | |
parent | 65f83941c39c14c2af9da5064393545ea2f7b3e5 (diff) |
Move GitHooksService to Gitlab::Git
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/hook.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/git/hooks_service.rb | 37 |
2 files changed, 39 insertions, 2 deletions
diff --git a/lib/gitlab/git/hook.rb b/lib/gitlab/git/hook.rb index 08cede42ba2..cc35d77c6e4 100644 --- a/lib/gitlab/git/hook.rb +++ b/lib/gitlab/git/hook.rb @@ -1,6 +1,6 @@ -# Gitaly note: JV: looks like this is only used by GitHooksService in +# Gitaly note: JV: looks like this is only used by Gitlab::Git::HooksService in # app/services. We shouldn't bother migrating this until we know how -# GitHooksService will be migrated. +# Gitlab::Git::HooksService will be migrated. module Gitlab module Git 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 + |