From 2e2a2034d1f5d76bd85c7a7b2a36a3d46b7eba9a Mon Sep 17 00:00:00 2001 From: Phillip Kuang Date: Mon, 18 Feb 2019 21:57:20 -0500 Subject: [PATCH] feat: add a new webhook event for contract_published --- lib/pact_broker/pacts/service.rb | 6 ++++-- lib/pact_broker/webhooks/webhook_event.rb | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/pact_broker/pacts/service.rb b/lib/pact_broker/pacts/service.rb index 70b059772..de0bf85d3 100644 --- a/lib/pact_broker/pacts/service.rb +++ b/lib/pact_broker/pacts/service.rb @@ -118,10 +118,11 @@ def update_pact params, existing_pact logger.debug "Content #{params[:json_content]}" updated_pact = pact_repository.update existing_pact.id, params + webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED if existing_pact.json_content != updated_pact.json_content webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED else - logger.debug "Pact has not changed since previous revision, not triggering webhooks" + logger.debug "Pact has not changed since previous version, not triggering webhooks for changed content" end updated_pact @@ -137,10 +138,11 @@ def create_pact params, version, provider def trigger_webhooks pact # TODO add tests for this + webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED if pact_is_new_or_pact_has_changed_since_previous_version?(pact) webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED else - logger.debug "Pact has not changed since previous version, not triggering webhooks" + logger.debug "Pact has not changed since previous version, not triggering webhooks for changed content" end end diff --git a/lib/pact_broker/webhooks/webhook_event.rb b/lib/pact_broker/webhooks/webhook_event.rb index 6c8244a22..d2c12fdd6 100644 --- a/lib/pact_broker/webhooks/webhook_event.rb +++ b/lib/pact_broker/webhooks/webhook_event.rb @@ -5,18 +5,23 @@ module PactBroker module Webhooks class WebhookEvent < Sequel::Model + CONTRACT_PUBLISHED = 'contract_published' CONTRACT_CONTENT_CHANGED = 'contract_content_changed' VERIFICATION_PUBLISHED = 'provider_verification_published' DEFAULT_EVENT_NAME = CONTRACT_CONTENT_CHANGED #CONTRACT_VERIFIABLE_CONTENT_CHANGED = 'contract_verifiable_content_changed' #VERIFICATION_STATUS_CHANGED = 'verification_status_changed' - EVENT_NAMES = [CONTRACT_CONTENT_CHANGED, VERIFICATION_PUBLISHED] + EVENT_NAMES = [CONTRACT_PUBLISHED, CONTRACT_CONTENT_CHANGED, VERIFICATION_PUBLISHED] dataset_module do include PactBroker::Repositories::Helpers end + def contract_published? + name == CONTRACT_PUBLISHED + end + def contract_content_changed? name == CONTRACT_CONTENT_CHANGED end