Skip to content

Commit 6fc78ff

Browse files
committed
feat(badge markdown): show message about enabling public badge access when disabled
1 parent cb6cb8e commit 6fc78ff

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

lib/pact_broker/api/renderers/html_pact_renderer.rb

+19-8
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def head
5050
def pact_metadata
5151
"<div class='pact-metadata'>
5252
<ul>
53-
#{badge_list_items}
53+
#{badge_list_item}
54+
#{badge_markdown_item}
5455
<li>
5556
<span class='name'>#{@pact.consumer.name} version:</span>
5657
<span class='value'>#{@pact.consumer_version_number}#{tags}</span>
@@ -69,20 +70,30 @@ def pact_metadata
6970
</div>"
7071
end
7172

72-
def badge_list_items
73-
if PactBroker.configuration.enable_public_badge_access
73+
def badge_list_item
7474
"<li class='badge'>
7575
<img src='#{badge_url}'/>
7676
</li>
77-
<li class='badge-markdown' style='display:none'>
78-
<textarea rows='3' cols='100'>#{badge_markdown}</textarea>
79-
</li>
8077
"
81-
end
78+
end
79+
80+
def badge_markdown_item
81+
"<li class='badge-markdown' style='display:none'>
82+
<textarea rows='3' cols='100'>#{badge_markdown}</textarea>
83+
</li>"
8284
end
8385

8486
def badge_markdown
85-
"[![#{@pact.consumer.name}/#{@pact.provider.name} Pact Status](#{badge_url})](#{badge_target_url})"
87+
warning = if badges_protected?
88+
"If the broker is protected by authentication, set `enable_public_badge_access` to true in the configuration to enable badges to be embedded in a markdown file.\n"
89+
else
90+
""
91+
end
92+
"#{warning}[![#{@pact.consumer.name}/#{@pact.provider.name} Pact Status](#{badge_url})](#{badge_target_url})"
93+
end
94+
95+
def badges_protected?
96+
!PactBroker.configuration.enable_public_badge_access
8697
end
8798

8899
def base_url

spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ module Renderers
6060
expect(subject).to include "[![Consumer/Provider Pact Status](http://badge)](http://base)"
6161
end
6262

63+
context "when enable_public_badge_access is false" do
64+
before do
65+
PactBroker.configuration.enable_public_badge_access = false
66+
end
67+
68+
it "renders a message instructing the user to turn public access on" do
69+
expect(subject).to include "set `enable_public_badge_access` to true in the configuration"
70+
end
71+
end
72+
6373
context "when the content is not a valid pact, but is still JSON" do
6474
before do
6575
allow(pact).to receive(:content_hash).and_return(content_hash)

0 commit comments

Comments
 (0)