lib/pact_broker/webhooks/service.rb in pact_broker-2.76.1 vs lib/pact_broker/webhooks/service.rb in pact_broker-2.76.2

- old
+ new

@@ -85,20 +85,20 @@ def self.find_all webhook_repository.find_all end - def self.test_execution webhook, execution_configuration + def self.test_execution webhook, event_context, execution_configuration merged_options = execution_configuration.with_failure_log_message("Webhook execution failed").to_hash verification = nil if webhook.trigger_on_provider_verification_published? verification = verification_service.search_for_latest(webhook.consumer_name, webhook.provider_name) || PactBroker::Verifications::PlaceholderVerification.new end pact = pact_service.search_for_latest_pact(consumer_name: webhook.consumer_name, provider_name: webhook.provider_name) || PactBroker::Pacts::PlaceholderPact.new - webhook.execute(pact, verification, merged_options) + webhook.execute(pact, verification, event_context.merge(event_name: "test"), merged_options) end def self.execute_triggered_webhook_now triggered_webhook, webhook_execution_configuration_hash webhook_execution_result = triggered_webhook.execute webhook_execution_configuration_hash webhook_repository.create_execution triggered_webhook, webhook_execution_result @@ -119,26 +119,27 @@ def self.find_by_consumer_and_provider consumer, provider webhook_repository.find_by_consumer_and_provider consumer, provider end - def self.trigger_webhooks pact, verification, event_name, options + def self.trigger_webhooks pact, verification, event_name, event_context, options webhooks = webhook_repository.find_by_consumer_and_or_provider_and_event_name pact.consumer, pact.provider, event_name if webhooks.any? webhook_execution_configuration = options.fetch(:webhook_execution_configuration).with_webhook_context(event_name: event_name) - run_later(webhooks, pact, verification, event_name, options.merge(webhook_execution_configuration: webhook_execution_configuration)) + # bit messy to merge in base_url here, but easier than a big refactor + base_url = options.fetch(:webhook_execution_configuration).webhook_context.fetch(:base_url) + run_later(webhooks, pact, verification, event_name, event_context.merge(event_name: event_name, base_url: base_url), options.merge(webhook_execution_configuration: webhook_execution_configuration)) else logger.info "No enabled webhooks found for consumer \"#{pact.consumer.name}\" and provider \"#{pact.provider.name}\" and event #{event_name}" end end - def self.run_later webhooks, pact, verification, event_name, options + def self.run_later webhooks, pact, verification, event_name, event_context, options trigger_uuid = next_uuid webhooks.each do | webhook | begin - webhook_context = options.fetch(:webhook_execution_configuration).webhook_context - triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, webhook, pact, verification, RESOURCE_CREATION, event_name, webhook_context) + triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, webhook, pact, verification, RESOURCE_CREATION, event_name, event_context) logger.info "Scheduling job for webhook with uuid #{webhook.uuid}" logger.debug "Schedule webhook with options #{options}" job_data = { triggered_webhook: triggered_webhook }.deep_merge(options) # Delay slightly to make sure the request transaction has finished before we execute the webhook Job.perform_in(5, job_data)