2015-11-25 19:20:40 -05:00
|
|
|
class GitHooksService
|
|
|
|
PreReceiveError = Class.new(StandardError)
|
|
|
|
|
2016-11-28 09:04:51 -05:00
|
|
|
attr_accessor :oldrev, :newrev, :ref
|
|
|
|
|
2015-11-25 19:20:40 -05:00
|
|
|
def execute(user, repo_path, oldrev, newrev, ref)
|
|
|
|
@repo_path = repo_path
|
2016-06-15 08:59:37 -04:00
|
|
|
@user = Gitlab::GlId.gl_id(user)
|
2015-11-25 19:20:40 -05:00
|
|
|
@oldrev = oldrev
|
|
|
|
@newrev = newrev
|
|
|
|
@ref = ref
|
|
|
|
|
2015-12-01 12:31:44 -05:00
|
|
|
%w(pre-receive update).each do |hook_name|
|
2016-07-04 08:30:22 -04:00
|
|
|
status, message = run_hook(hook_name)
|
|
|
|
|
|
|
|
unless status
|
|
|
|
raise PreReceiveError, message
|
2015-12-01 12:31:44 -05:00
|
|
|
end
|
2015-11-25 19:20:40 -05:00
|
|
|
end
|
2015-12-01 12:31:44 -05:00
|
|
|
|
2017-01-26 06:35:19 -05:00
|
|
|
yield(self).tap do
|
|
|
|
run_hook('post-receive')
|
|
|
|
end
|
2015-11-25 19:20:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def run_hook(name)
|
|
|
|
hook = Gitlab::Git::Hook.new(name, @repo_path)
|
2016-11-28 09:04:51 -05:00
|
|
|
hook.trigger(@user, oldrev, newrev, ref)
|
2015-11-25 19:20:40 -05:00
|
|
|
end
|
|
|
|
end
|