Commit 9f7811e4 authored by Alexis Reigel's avatar Alexis Reigel Committed by Alexis Reigel

execute system hooks from project

parent fb583c4b
...@@ -2,7 +2,8 @@ class SystemHook < WebHook ...@@ -2,7 +2,8 @@ class SystemHook < WebHook
TRIGGERS = { TRIGGERS = {
repository_update_hooks: :repository_update_events, repository_update_hooks: :repository_update_events,
push_hooks: :push_events, push_hooks: :push_events,
tag_push_hooks: :tag_push_events tag_push_hooks: :tag_push_events,
merge_request_hooks: :merge_requests_events
}.freeze }.freeze
TRIGGERS.each do |trigger, event| TRIGGERS.each do |trigger, event|
...@@ -11,4 +12,5 @@ class SystemHook < WebHook ...@@ -11,4 +12,5 @@ class SystemHook < WebHook
default_value_for :push_events, false default_value_for :push_events, false
default_value_for :repository_update_events, true default_value_for :repository_update_events, true
default_value_for :merge_requests_events, false
end end
...@@ -974,6 +974,10 @@ class Project < ActiveRecord::Base ...@@ -974,6 +974,10 @@ class Project < ActiveRecord::Base
hook.async_execute(data, hooks_scope.to_s) hook.async_execute(data, hooks_scope.to_s)
end end
end end
SystemHook.public_send(hooks_scope).each do |hook| # rubocop:disable GitlabSecurity/PublicSend
hook.async_execute(data, hooks_scope.to_s)
end
end end
def execute_services(data, hooks_scope = :push_hooks) def execute_services(data, hooks_scope = :push_hooks)
......
...@@ -7,7 +7,8 @@ describe SystemHook do ...@@ -7,7 +7,8 @@ describe SystemHook do
it 'sets defined default parameters' do it 'sets defined default parameters' do
attrs = { attrs = {
push_events: false, push_events: false,
repository_update_events: true repository_update_events: true,
merge_requests_events: false
} }
expect(system_hook).to have_attributes(attrs) expect(system_hook).to have_attributes(attrs)
end end
......
...@@ -3177,4 +3177,27 @@ describe Project do ...@@ -3177,4 +3177,27 @@ describe Project do
expect { project.write_repository_config }.not_to raise_error expect { project.write_repository_config }.not_to raise_error
end end
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 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