Commit 3ffbf03c authored by Vladimir Shushlin's avatar Vladimir Shushlin Committed by Bob Van Landuyt

Fire webhook on new deployment

parent 07796207
......@@ -12,7 +12,8 @@ module TriggerableHooks
merge_request_hooks: :merge_requests_events,
job_hooks: :job_events,
pipeline_hooks: :pipeline_events,
wiki_page_hooks: :wiki_page_events
wiki_page_hooks: :wiki_page_events,
deployment_hooks: :deployment_events
}.freeze
extend ActiveSupport::Concern
......
......@@ -148,6 +148,7 @@ class Deployment < ApplicationRecord
def execute_hooks
deployment_data = Gitlab::DataBuilder::Deployment.build(self)
project.execute_hooks(deployment_data, :deployment_hooks) if Feature.enabled?(:deployment_webhooks, project)
project.execute_services(deployment_data, :deployment_hooks)
end
......
......@@ -17,7 +17,8 @@ class ProjectHook < WebHook
:merge_request_hooks,
:job_hooks,
:pipeline_hooks,
:wiki_page_hooks
:wiki_page_hooks,
:deployment_hooks
]
belongs_to :project
......
......@@ -49,5 +49,29 @@ RSpec.describe Deployments::FinishedWorker do
expect(ProjectServiceWorker).not_to have_received(:perform_async)
end
it 'execute webhooks' do
deployment = create(:deployment)
project = deployment.project
web_hook = create(:project_hook, deployment_events: true, project: project)
expect_next_instance_of(WebHookService, web_hook, an_instance_of(Hash), "deployment_hooks") do |service|
expect(service).to receive(:async_execute)
end
worker.perform(deployment.id)
end
it 'does not execute webhooks if feature flag is disabled' do
stub_feature_flags(deployment_webhooks: false)
deployment = create(:deployment)
project = deployment.project
create(:project_hook, deployment_events: true, project: project)
expect(WebHookService).not_to receive(:new)
worker.perform(deployment.id)
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