Skip to content

Commit 0471397

Browse files
committed
feat: update descriptions for new consumer version selectors
1 parent 6dac2ac commit 0471397

File tree

2 files changed

+91
-5
lines changed

2 files changed

+91
-5
lines changed

lib/pact/pact_broker/pact_selection_description.rb

+41-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,48 @@ def pact_selection_description(provider, consumer_version_selectors, options, br
55
message = "Fetching pacts for #{provider} from #{broker_base_url} with the selection criteria: "
66
if consumer_version_selectors.any?
77
desc = consumer_version_selectors.collect do |selector|
8-
all_or_latest = !selector[:latest] ? "all for tag" : "latest for tag"
9-
consumer = selector[:consumer] ? "of consumer #{selector[:consumer]}" : nil
8+
desc = nil
9+
if selector[:tag]
10+
desc = !selector[:latest] ? "all for tag #{selector[:tag]}" : "latest for tag #{selector[:tag]}"
11+
desc = "#{desc} of #{selector[:consumer]}" if selector[:consumer]
12+
elsif selector[:branch]
13+
desc = "latest from branch #{selector[:branch]}"
14+
desc = "#{desc} of #{selector[:consumer]}" if selector[:consumer]
15+
elsif selector[:mainBranch]
16+
desc = "latest from main branch"
17+
desc = "#{desc} of #{selector[:consumer]}" if selector[:consumer]
18+
elsif selector[:deployed]
19+
if selector[:environment]
20+
desc = "currently deployed to #{selector[:environment]}"
21+
else
22+
desc = "currently deployed"
23+
end
24+
desc = "#{selector[:consumer]} #{desc}" if selector[:consumer]
25+
elsif selector[:released]
26+
if selector[:environment]
27+
desc = "currently released to #{selector[:environment]}"
28+
else
29+
desc = "currently released"
30+
end
31+
desc = "#{selector[:consumer]} #{desc}" if selector[:consumer]
32+
elsif selector[:deployedOrReleased]
33+
if selector[:environment]
34+
desc = "currently deployed or released to #{selector[:environment]}"
35+
else
36+
desc = "currently deployed or released"
37+
end
38+
desc = "#{selector[:consumer]} #{desc}" if selector[:consumer]
39+
elsif selector[:environment]
40+
desc = "currently in #{selector[:environment]}"
41+
desc = "#{selector[:consumer]} #{desc}" if selector[:consumer]
42+
else
43+
desc = selector.to_s
44+
end
45+
1046
fallback = selector[:fallback] || selector[:fallbackTag]
11-
name = fallback ? "#{selector[:tag]} (or #{fallback} if not found)" : selector[:tag]
12-
[all_or_latest, name, consumer].compact.join(" ")
47+
desc = "#{desc} (or #{fallback} if not found)" if fallback
48+
49+
desc
1350
end.join(", ")
1451
if options[:include_wip_pacts_since]
1552
desc = "#{desc}, work in progress pacts created after #{options[:include_wip_pacts_since]}"

spec/lib/pact/pact_broker/pact_selection_description_spec.rb

+50-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,56 @@ module PactBroker
2222
describe "when consumer selector specifies a consumer name" do
2323
let(:consumer_version_selectors) { [{ tag: "cmaster", latest: true, consumer: "Foo" }] }
2424

25-
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" }
25+
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" }
26+
end
27+
28+
describe "for branch" do
29+
let(:consumer_version_selectors) { [{ branch: "feat/x", consumer: "Foo" }] }
30+
31+
it { is_expected.to include "latest from branch feat/x of Foo" }
32+
end
33+
34+
describe "for main branch" do
35+
let(:consumer_version_selectors) { [{ mainBranch: true, consumer: "Foo" }] }
36+
37+
it { is_expected.to include "latest from main branch of Foo" }
38+
end
39+
40+
describe "for deployedOrReleased" do
41+
let(:consumer_version_selectors) { [{ deployedOrReleased: true }] }
42+
43+
it { is_expected.to include "currently deployed or released" }
44+
end
45+
46+
describe "for released in environment" do
47+
let(:consumer_version_selectors) { [{ released: true, environment: "production" }] }
48+
49+
it { is_expected.to include "currently released to production" }
50+
end
51+
52+
describe "for deployed in environment" do
53+
let(:consumer_version_selectors) { [{ deployed: true, environment: "production" }] }
54+
55+
it { is_expected.to include "currently deployed to production" }
56+
end
57+
58+
describe "for deployedOrReleased in environment" do
59+
let(:consumer_version_selectors) { [{ deployedOrReleased: true, environment: "production" }] }
60+
61+
it { is_expected.to include "currently deployed or released to production" }
62+
end
63+
64+
describe "in environment" do
65+
let(:consumer_version_selectors) { [{ environment: "production" }] }
66+
67+
it { is_expected.to include "in production" }
68+
end
69+
70+
describe "unknown" do
71+
let(:consumer_version_selectors) { [{ branchPattern: "*foo" }] }
72+
73+
it { is_expected.to include "branchPattern" }
74+
it { is_expected.to include "*foo" }
2675
end
2776
end
2877
end

0 commit comments

Comments
 (0)