Skip to content

Commit c581929

Browse files
committed
fix(can-i-deploy): when multiple selectors are specified, do not infer integrations unless the "latest" or "tag" are specified
1 parent 1aef462 commit c581929

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

lib/pact_broker/matrix/quick_row.rb

+10-4
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,19 @@ class QuickRow < Sequel::Model(Sequel.as(:latest_pact_publication_ids_for_consum
8383
select *SELECT_ALL_COLUMN_ARGS
8484
select *SELECT_PACTICIPANT_IDS_ARGS
8585

86-
def distinct_integrations selectors
86+
def distinct_integrations selectors, infer_integrations
8787
query = if selectors.size == 1
8888
pacticipant_ids_matching_one_selector_optimised(selectors)
8989
else
90-
select_pacticipant_ids
91-
.distinct
92-
.matching_any_of_multiple_selectors(selectors)
90+
if infer_integrations
91+
select_pacticipant_ids
92+
.distinct
93+
.matching_any_of_multiple_selectors(selectors)
94+
else
95+
select_pacticipant_ids
96+
.distinct
97+
.matching_multiple_selectors(selectors)
98+
end
9399
end
94100

95101
query.from_self(alias: :pacticipant_ids)

lib/pact_broker/matrix/repository.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def find_ids_for_pacticipant_names params
5555
# Return the latest matrix row (pact/verification) for each consumer_version_number/provider_version_number
5656
def find specified_selectors, options = {}
5757
resolved_specified_selectors = resolve_versions_and_add_ids(specified_selectors, :specified)
58-
integrations = find_integrations_for_specified_selectors(resolved_specified_selectors)
58+
integrations = find_integrations_for_specified_selectors(resolved_specified_selectors, infer_selectors_for_integrations?(options))
5959
resolved_selectors = if infer_selectors_for_integrations?(options)
6060
resolved_specified_selectors + inferred_selectors(resolved_specified_selectors, integrations, options)
6161
else
@@ -84,12 +84,10 @@ def find_compatible_pacticipant_versions selectors
8484
find(selectors, latestby: 'cvpv').select(&:success)
8585
end
8686

87-
# If one pacticipant is specified, find all the integrations that involve that pacticipant
88-
# If two or more are specified, just return the integrations that involve the specified pacticipants
89-
def find_integrations_for_specified_selectors(resolved_specified_selectors)
87+
def find_integrations_for_specified_selectors(resolved_specified_selectors, infer_integrations)
9088
specified_pacticipant_names = resolved_specified_selectors.collect(&:pacticipant_name)
9189
QuickRow
92-
.distinct_integrations(resolved_specified_selectors)
90+
.distinct_integrations(resolved_specified_selectors, infer_integrations)
9391
.collect(&:to_hash)
9492
.collect do | hash |
9593
required = is_a_row_for_this_integration_required?(specified_pacticipant_names, hash[:consumer_name])

spec/lib/pact_broker/matrix/integration_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,27 @@ module Matrix
395395
end
396396
end
397397
end
398+
399+
describe "when there is a consumer with two providers, and only one of them has a verification, and the consumer and the verified provider are explicitly specified" do
400+
before do
401+
td.create_pact_with_verification("Foo", "1", "Bar", "2")
402+
.create_provider_version_tag("prod")
403+
.create_pact_with_hierarchy("Foo", "1", "Wiffle")
404+
end
405+
406+
let(:selectors) do
407+
[
408+
{ pacticipant_name: "Foo", pacticipant_version_number: "1" },
409+
{ pacticipant_name: "Bar", tag: "prod", latest: true}
410+
]
411+
end
412+
413+
let(:options) { { latestby: "cvpv"} }
414+
415+
it "should allow the consumer to be deployed" do
416+
expect(subject.deployment_status_summary).to be_deployable
417+
end
418+
end
398419
end
399420
end
400421
end

0 commit comments

Comments
 (0)