2018-07-05 06:18:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-20 05:53:15 -05:00
|
|
|
class SystemHooksService
|
2014-01-15 07:26:05 -05:00
|
|
|
def execute_hooks_for(model, event)
|
2017-11-29 10:30:17 -05:00
|
|
|
data = build_event_data(model, event)
|
|
|
|
|
|
|
|
model.run_after_commit_or_now do
|
|
|
|
SystemHooksService.new.execute_hooks(data)
|
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|
|
|
|
|
2016-04-15 07:08:22 -04:00
|
|
|
def execute_hooks(data, hooks_scope = :all)
|
2021-05-06 17:10:07 -04:00
|
|
|
SystemHook.executable.hooks_for(hooks_scope).find_each do |hook|
|
2016-04-15 07:08:22 -04:00
|
|
|
hook.async_execute(data, 'system_hooks')
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|
2018-02-08 10:51:02 -05:00
|
|
|
|
2020-01-16 10:08:41 -05:00
|
|
|
Gitlab::FileHook.execute_all_async(data)
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|
|
|
|
|
2016-04-15 07:08:22 -04:00
|
|
|
private
|
2013-02-20 06:33:03 -05:00
|
|
|
|
2014-01-15 07:26:05 -05:00
|
|
|
def build_event_data(model, event)
|
2021-01-21 16:08:47 -05:00
|
|
|
builder_class = case model
|
|
|
|
when GroupMember
|
|
|
|
Gitlab::HookData::GroupMemberBuilder
|
|
|
|
when Group
|
|
|
|
Gitlab::HookData::GroupBuilder
|
2021-03-02 16:11:07 -05:00
|
|
|
when ProjectMember
|
|
|
|
Gitlab::HookData::ProjectMemberBuilder
|
2021-04-07 11:09:18 -04:00
|
|
|
when User
|
|
|
|
Gitlab::HookData::UserBuilder
|
2021-04-20 14:09:37 -04:00
|
|
|
when Project
|
|
|
|
Gitlab::HookData::ProjectBuilder
|
2021-04-23 08:09:52 -04:00
|
|
|
when Key
|
|
|
|
Gitlab::HookData::KeyBuilder
|
2021-01-21 16:08:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
builder_class.new(model).build(event)
|
2020-12-02 10:09:37 -05:00
|
|
|
end
|
2013-02-20 05:53:15 -05:00
|
|
|
end
|