Skip to content

Commit 73a06ff

Browse files
committed
fix: correctly trigger contract_content_changed webhooks when first version of a pact is published
1 parent e19c9c9 commit 73a06ff

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/pact_broker/pacts/service.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ def find_distinct_pacts_between consumer, options
9494
distinct
9595
end
9696

97-
def pact_has_changed_since_previous_version? pact
97+
# TODO also take into account overridden revisions
98+
def pact_is_new_or_pact_has_changed_since_previous_version? pact
9899
previous_pact = pact_repository.find_previous_pact pact
99-
previous_pact && pact.json_content != previous_pact.json_content
100+
previous_pact.nil? || pact.json_content != previous_pact.json_content
100101
end
101102

102103
private
@@ -108,6 +109,8 @@ def update_pact params, existing_pact
108109

109110
if existing_pact.json_content != updated_pact.json_content
110111
webhook_service.execute_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED
112+
else
113+
logger.debug "Pact has not changed since previous revision, not triggering webhooks"
111114
end
112115

113116
updated_pact
@@ -122,8 +125,11 @@ def create_pact params, version, provider
122125
end
123126

124127
def trigger_webhooks pact
125-
if pact_has_changed_since_previous_version? pact
128+
# TODO add tests for this
129+
if pact_is_new_or_pact_has_changed_since_previous_version?(pact)
126130
webhook_service.execute_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED
131+
else
132+
logger.debug "Pact has not changed since previous version, not triggering webhooks"
127133
end
128134
end
129135
end

spec/lib/pact_broker/pacts/service_spec.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ module Pacts
3030

3131
end
3232

33-
describe "#pact_has_changed_since_previous_version?" do
33+
describe "#pact_is_new_or_pact_has_changed_since_previous_version?" do
3434
let(:json_content) { { 'some' => 'json'}.to_json }
3535
let(:pact) { instance_double(PactBroker::Domain::Pact, json_content: json_content)}
3636

3737
before do
3838
allow_any_instance_of(Pacts::Repository).to receive(:find_previous_pact).and_return(previous_pact)
3939
end
4040

41-
subject { Service.pact_has_changed_since_previous_version? pact }
41+
subject { Service.pact_is_new_or_pact_has_changed_since_previous_version? pact }
4242

4343
context "when a previous pact is found" do
4444
let(:previous_pact) { instance_double(PactBroker::Domain::Pact, json_content: previous_json_content)}
@@ -60,8 +60,9 @@ module Pacts
6060

6161
context "when a previous pact is not found" do
6262
let(:previous_pact) { nil }
63-
it "returns false" do
64-
expect(subject).to be_falsey
63+
64+
it "returns true" do
65+
expect(subject).to be_truthy
6566
end
6667
end
6768
end

0 commit comments

Comments
 (0)