Read about our upcoming Code of Conduct on this issue

Commit 6dc477a2 authored by Alexis Reigel's avatar Alexis Reigel Committed by Alexis Reigel
Browse files

execute system hooks from project

parent 49a91dfdb8df
......@@ -2,7 +2,8 @@ class SystemHook < WebHook
TRIGGERS = {
repository_update_hooks: :repository_update_events,
push_hooks: :push_events,
tag_push_hooks: :tag_push_events
tag_push_hooks: :tag_push_events,
merge_request_hooks: :merge_requests_events
}.freeze
TRIGGERS.each do |trigger, event|
......@@ -11,4 +12,5 @@ class SystemHook < WebHook
default_value_for :push_events, false
default_value_for :repository_update_events, true
default_value_for :merge_requests_events, false
end
......@@ -974,6 +974,10 @@ def execute_hooks(data, hooks_scope = :push_hooks)
hook.async_execute(data, hooks_scope.to_s)
end
end
SystemHook.public_send(hooks_scope).each do |hook| # rubocop:disable GitlabSecurity/PublicSend
hook.async_execute(data, hooks_scope.to_s)
end
end
def execute_services(data, hooks_scope = :push_hooks)
......
......@@ -7,7 +7,8 @@
it 'sets defined default parameters' do
attrs = {
push_events: false,
repository_update_events: true
repository_update_events: true,
merge_requests_events: false
}
expect(system_hook).to have_attributes(attrs)
end
......
......@@ -3177,4 +3177,27 @@ def enable_lfs
expect { project.write_repository_config }.not_to raise_error
end
end
describe '#execute_hooks' do
it 'executes the projects hooks with the specified scope' do
hook1 = create(:project_hook, merge_requests_events: true, tag_push_events: false)
hook2 = create(:project_hook, merge_requests_events: false, tag_push_events: true)
project = create(:project, hooks: [hook1, hook2])
expect_any_instance_of(ProjectHook).to receive(:async_execute).once
project.execute_hooks({}, :tag_push_hooks)
end
it 'executes the system hooks with the specified scope' do
create :system_hook, merge_requests_events: true, tag_push_events: false
create :system_hook, merge_requests_events: false, tag_push_events: true
allow_any_instance_of(SystemHook).to receive(:async_execute).once
project = create :project
expect_any_instance_of(SystemHook).to receive(:async_execute).once
project.execute_hooks({}, :tag_push_hooks)
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment