diff --git a/lib/pact/pact_broker/pact_selection_description.rb b/lib/pact/pact_broker/pact_selection_description.rb index 2d8ed886..369dc891 100644 --- a/lib/pact/pact_broker/pact_selection_description.rb +++ b/lib/pact/pact_broker/pact_selection_description.rb @@ -5,11 +5,48 @@ def pact_selection_description(provider, consumer_version_selectors, options, br message = "Fetching pacts for #{provider} from #{broker_base_url} with the selection criteria: " if consumer_version_selectors.any? desc = consumer_version_selectors.collect do |selector| - all_or_latest = !selector[:latest] ? "all for tag" : "latest for tag" - consumer = selector[:consumer] ? "of consumer #{selector[:consumer]}" : nil + desc = nil + if selector[:tag] + desc = !selector[:latest] ? "all for tag #{selector[:tag]}" : "latest for tag #{selector[:tag]}" + desc = "#{desc} of #{selector[:consumer]}" if selector[:consumer] + elsif selector[:branch] + desc = "latest from branch #{selector[:branch]}" + desc = "#{desc} of #{selector[:consumer]}" if selector[:consumer] + elsif selector[:mainBranch] + desc = "latest from main branch" + desc = "#{desc} of #{selector[:consumer]}" if selector[:consumer] + elsif selector[:deployed] + if selector[:environment] + desc = "currently deployed to #{selector[:environment]}" + else + desc = "currently deployed" + end + desc = "#{selector[:consumer]} #{desc}" if selector[:consumer] + elsif selector[:released] + if selector[:environment] + desc = "currently released to #{selector[:environment]}" + else + desc = "currently released" + end + desc = "#{selector[:consumer]} #{desc}" if selector[:consumer] + elsif selector[:deployedOrReleased] + if selector[:environment] + desc = "currently deployed or released to #{selector[:environment]}" + else + desc = "currently deployed or released" + end + desc = "#{selector[:consumer]} #{desc}" if selector[:consumer] + elsif selector[:environment] + desc = "currently in #{selector[:environment]}" + desc = "#{selector[:consumer]} #{desc}" if selector[:consumer] + else + desc = selector.to_s + end + fallback = selector[:fallback] || selector[:fallbackTag] - name = fallback ? "#{selector[:tag]} (or #{fallback} if not found)" : selector[:tag] - [all_or_latest, name, consumer].compact.join(" ") + desc = "#{desc} (or #{fallback} if not found)" if fallback + + desc end.join(", ") if options[:include_wip_pacts_since] desc = "#{desc}, work in progress pacts created after #{options[:include_wip_pacts_since]}" diff --git a/spec/lib/pact/pact_broker/pact_selection_description_spec.rb b/spec/lib/pact/pact_broker/pact_selection_description_spec.rb index 824af997..98e5e47b 100644 --- a/spec/lib/pact/pact_broker/pact_selection_description_spec.rb +++ b/spec/lib/pact/pact_broker/pact_selection_description_spec.rb @@ -22,7 +22,56 @@ module PactBroker describe "when consumer selector specifies a consumer name" do let(:consumer_version_selectors) { [{ tag: "cmaster", latest: true, consumer: "Foo" }] } - it { is_expected.to eq "Fetching pacts for Bar from http://broker with the selection criteria: latest for tag cmaster of consumer Foo, work in progress pacts created after 2020-01-01" } + it { is_expected.to eq "Fetching pacts for Bar from http://broker with the selection criteria: latest for tag cmaster of Foo, work in progress pacts created after 2020-01-01" } + end + + describe "for branch" do + let(:consumer_version_selectors) { [{ branch: "feat/x", consumer: "Foo" }] } + + it { is_expected.to include "latest from branch feat/x of Foo" } + end + + describe "for main branch" do + let(:consumer_version_selectors) { [{ mainBranch: true, consumer: "Foo" }] } + + it { is_expected.to include "latest from main branch of Foo" } + end + + describe "for deployedOrReleased" do + let(:consumer_version_selectors) { [{ deployedOrReleased: true }] } + + it { is_expected.to include "currently deployed or released" } + end + + describe "for released in environment" do + let(:consumer_version_selectors) { [{ released: true, environment: "production" }] } + + it { is_expected.to include "currently released to production" } + end + + describe "for deployed in environment" do + let(:consumer_version_selectors) { [{ deployed: true, environment: "production" }] } + + it { is_expected.to include "currently deployed to production" } + end + + describe "for deployedOrReleased in environment" do + let(:consumer_version_selectors) { [{ deployedOrReleased: true, environment: "production" }] } + + it { is_expected.to include "currently deployed or released to production" } + end + + describe "in environment" do + let(:consumer_version_selectors) { [{ environment: "production" }] } + + it { is_expected.to include "in production" } + end + + describe "unknown" do + let(:consumer_version_selectors) { [{ branchPattern: "*foo" }] } + + it { is_expected.to include "branchPattern" } + it { is_expected.to include "*foo" } end end end