gitlab-org--gitlab-foss/lib/gitlab/git/hooks_service.rb

36 lines
817 B
Ruby
Raw Normal View History

2017-08-22 08:18:09 -04:00
module Gitlab
module Git
class HooksService
attr_accessor :oldrev, :newrev, :ref
2017-08-22 10:27:15 -04:00
def execute(pusher, repository, oldrev, newrev, ref)
@repository = repository
@gl_id = pusher.gl_id
@gl_username = pusher.username
@oldrev = oldrev
@newrev = newrev
@ref = ref
2017-08-22 10:27:15 -04:00
2017-08-22 08:18:09 -04:00
%w(pre-receive update).each do |hook_name|
status, message = run_hook(hook_name)
2017-08-22 10:27:15 -04:00
2017-08-22 08:18:09 -04:00
unless status
raise PreReceiveError, message
end
end
2017-08-22 10:27:15 -04:00
2017-08-22 08:18:09 -04:00
yield(self).tap do
run_hook('post-receive')
end
end
2017-08-22 10:27:15 -04:00
2017-08-22 08:18:09 -04:00
private
2017-08-22 10:27:15 -04:00
2017-08-22 08:18:09 -04:00
def run_hook(name)
hook = Gitlab::Git::Hook.new(name, @repository)
hook.trigger(@gl_id, @gl_username, oldrev, newrev, ref)
2017-08-22 08:18:09 -04:00
end
end
end
end