execute system hooks from project

This commit is contained in:
Alexis Reigel 2017-09-13 17:17:34 +02:00 committed by Alexis Reigel
parent fb583c4b18
commit 9f7811e474
4 changed files with 32 additions and 2 deletions

View file

@ -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

View file

@ -974,6 +974,10 @@ class Project < ActiveRecord::Base
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)

View file

@ -7,7 +7,8 @@ describe SystemHook do
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

View file

@ -3177,4 +3177,27 @@ describe Project do
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