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
|
|
|
|
2017-08-02 14:14:50 -04:00
|
|
|
def execute(pusher, repository, oldrev, newrev, ref)
|
|
|
|
@repository = repository
|
|
|
|
@gl_id = pusher.gl_id
|
2017-10-25 13:01:57 -04:00
|
|
|
@gl_username = pusher.username
|
2017-08-02 14:14:50 -04:00
|
|
|
@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)
|
2017-08-02 14:14:50 -04:00
|
|
|
hook.trigger(@gl_id, @gl_username, oldrev, newrev, ref)
|
2017-08-22 08:18:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|