summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Reigel <mail@koffeinfrei.org>2017-09-13 17:17:34 +0200
committerAlexis Reigel <alexis.reigel.ext@siemens.com>2018-01-04 09:33:41 +0100
commit9f7811e474a3f3f54f4624d19ec982239518ed67 (patch)
tree68d387303a19d21787f056b63218b81800366e9d
parentfb583c4b1839af16c50e27105a300695aa50bcad (diff)
downloadgitlab-ce-9f7811e474a3f3f54f4624d19ec982239518ed67.tar.gz
execute system hooks from project
-rw-r--r--app/models/hooks/system_hook.rb4
-rw-r--r--app/models/project.rb4
-rw-r--r--spec/models/hooks/system_hook_spec.rb3
-rw-r--r--spec/models/project_spec.rb23
4 files changed, 32 insertions, 2 deletions
diff --git a/app/models/hooks/system_hook.rb b/app/models/hooks/system_hook.rb
index 180c479c41b..78b053f36c3 100644
--- a/app/models/hooks/system_hook.rb
+++ b/app/models/hooks/system_hook.rb
@@ -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
diff --git a/app/models/project.rb b/app/models/project.rb
index 9c0bbf697e2..a196c8b5c09 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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)
diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb
index 0e965f541d8..8bc45715dcd 100644
--- a/spec/models/hooks/system_hook_spec.rb
+++ b/spec/models/hooks/system_hook_spec.rb
@@ -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
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index cea22bbd184..339186e25ae 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -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