Skip to content

Commit

Permalink
feat: add a new webhook event for contract_published
Browse files Browse the repository at this point in the history
  • Loading branch information
kuangp committed Mar 4, 2019
1 parent 7238bc4 commit 2e2a203
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/pact_broker/pacts/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
7 changes: 6 additions & 1 deletion lib/pact_broker/webhooks/webhook_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e2a203

Please sign in to comment.