Skip to content

Commit 2e2a203

Browse files
committed
feat: add a new webhook event for contract_published
1 parent 7238bc4 commit 2e2a203

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/pact_broker/pacts/service.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ def update_pact params, existing_pact
118118
logger.debug "Content #{params[:json_content]}"
119119
updated_pact = pact_repository.update existing_pact.id, params
120120

121+
webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED
121122
if existing_pact.json_content != updated_pact.json_content
122123
webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED
123124
else
124-
logger.debug "Pact has not changed since previous revision, not triggering webhooks"
125+
logger.debug "Pact has not changed since previous version, not triggering webhooks for changed content"
125126
end
126127

127128
updated_pact
@@ -137,10 +138,11 @@ def create_pact params, version, provider
137138

138139
def trigger_webhooks pact
139140
# TODO add tests for this
141+
webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED
140142
if pact_is_new_or_pact_has_changed_since_previous_version?(pact)
141143
webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED
142144
else
143-
logger.debug "Pact has not changed since previous version, not triggering webhooks"
145+
logger.debug "Pact has not changed since previous version, not triggering webhooks for changed content"
144146
end
145147
end
146148

lib/pact_broker/webhooks/webhook_event.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@ module PactBroker
55
module Webhooks
66
class WebhookEvent < Sequel::Model
77

8+
CONTRACT_PUBLISHED = 'contract_published'
89
CONTRACT_CONTENT_CHANGED = 'contract_content_changed'
910
VERIFICATION_PUBLISHED = 'provider_verification_published'
1011
DEFAULT_EVENT_NAME = CONTRACT_CONTENT_CHANGED
1112
#CONTRACT_VERIFIABLE_CONTENT_CHANGED = 'contract_verifiable_content_changed'
1213
#VERIFICATION_STATUS_CHANGED = 'verification_status_changed'
1314

14-
EVENT_NAMES = [CONTRACT_CONTENT_CHANGED, VERIFICATION_PUBLISHED]
15+
EVENT_NAMES = [CONTRACT_PUBLISHED, CONTRACT_CONTENT_CHANGED, VERIFICATION_PUBLISHED]
1516

1617
dataset_module do
1718
include PactBroker::Repositories::Helpers
1819
end
1920

21+
def contract_published?
22+
name == CONTRACT_PUBLISHED
23+
end
24+
2025
def contract_content_changed?
2126
name == CONTRACT_CONTENT_CHANGED
2227
end

0 commit comments

Comments
 (0)