debian-mirror-gitlab/app/services/git_hooks_service.rb

31 lines
622 B
Ruby
Raw Normal View History

2015-12-23 02:04:40 +05:30
class GitHooksService
PreReceiveError = Class.new(StandardError)
def execute(user, repo_path, oldrev, newrev, ref)
@repo_path = repo_path
@user = Gitlab::GlId.gl_id(user)
2015-12-23 02:04:40 +05:30
@oldrev = oldrev
@newrev = newrev
@ref = ref
%w(pre-receive update).each do |hook_name|
2016-08-24 12:49:21 +05:30
status, message = run_hook(hook_name)
unless status
raise PreReceiveError, message
2015-12-23 02:04:40 +05:30
end
end
yield
run_hook('post-receive')
end
private
def run_hook(name)
hook = Gitlab::Git::Hook.new(name, @repo_path)
hook.trigger(@user, @oldrev, @newrev, @ref)
end
end