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

33 lines
675 B
Ruby
Raw Normal View History

2015-12-23 02:04:40 +05:30
class GitHooksService
PreReceiveError = Class.new(StandardError)
2017-01-15 13:20:01 +05:30
attr_accessor :oldrev, :newrev, :ref
2017-09-10 17:25:29 +05:30
def execute(user, project, oldrev, newrev, ref)
@project = project
@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
2017-08-17 22:00:37 +05:30
yield(self).tap do
run_hook('post-receive')
end
2015-12-23 02:04:40 +05:30
end
private
def run_hook(name)
2017-09-10 17:25:29 +05:30
hook = Gitlab::Git::Hook.new(name, @project)
2017-01-15 13:20:01 +05:30
hook.trigger(@user, oldrev, newrev, ref)
2015-12-23 02:04:40 +05:30
end
end