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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.1 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
class SystemHooksService
def execute_hooks_for(model, event)
2018-03-17 18:26:18 +05:30
data = build_event_data(model, event)
model.run_after_commit_or_now do
SystemHooksService.new.execute_hooks(data)
end
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
def execute_hooks(data, hooks_scope = :all)
2021-06-08 01:23:25 +05:30
SystemHook.executable.hooks_for(hooks_scope).find_each do |hook|
2016-06-02 11:05:42 +05:30
hook.async_execute(data, 'system_hooks')
2014-09-02 18:07:02 +05:30
end
2018-03-27 19:54:05 +05:30
2020-03-13 15:44:24 +05:30
Gitlab::FileHook.execute_all_async(data)
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
private
2014-09-02 18:07:02 +05:30
def build_event_data(model, event)
2021-03-11 19:13:27 +05:30
builder_class = case model
when GroupMember
Gitlab::HookData::GroupMemberBuilder
when Group
Gitlab::HookData::GroupBuilder
2021-04-17 20:07:23 +05:30
when ProjectMember
Gitlab::HookData::ProjectMemberBuilder
2021-04-29 21:17:54 +05:30
when User
Gitlab::HookData::UserBuilder
2021-06-08 01:23:25 +05:30
when Project
Gitlab::HookData::ProjectBuilder
when Key
Gitlab::HookData::KeyBuilder
2021-03-11 19:13:27 +05:30
end
builder_class.new(model).build(event)
2021-02-22 17:27:13 +05:30
end
2014-09-02 18:07:02 +05:30
end