diff --git a/lib/pact_broker/api/contracts/webhook_contract.rb b/lib/pact_broker/api/contracts/webhook_contract.rb index f462472f5..e8357ea53 100644 --- a/lib/pact_broker/api/contracts/webhook_contract.rb +++ b/lib/pact_broker/api/contracts/webhook_contract.rb @@ -142,7 +142,7 @@ def host_whitelist end def parse_uri(uri_string, placeholder = 'placeholder') - URI(uri_string.gsub(PactBroker::Webhooks::Render::TEMPLATE_PARAMETER_REGEXP, placeholder)) + URI(PactBroker::Webhooks::Render.render_with_placeholder(uri_string, placeholder)) end end diff --git a/lib/pact_broker/webhooks/render.rb b/lib/pact_broker/webhooks/render.rb index 0f59c2468..c64767eff 100644 --- a/lib/pact_broker/webhooks/render.rb +++ b/lib/pact_broker/webhooks/render.rb @@ -3,7 +3,6 @@ module PactBroker module Webhooks class Render - TEMPLATE_PARAMETER_REGEXP = /\$\{pactbroker\.[^\}]+\}/ DEFAULT_ESCAPER = lambda { |it| it } @@ -11,10 +10,16 @@ def self.includes_parameter?(value) value =~ TEMPLATE_PARAMETER_REGEXP end + def self.render_with_placeholder(value, placeholder = 'placeholder') + value.gsub(TEMPLATE_PARAMETER_REGEXP, placeholder) + end + def self.call(template, params, &escaper) render_template(escape_params(params, escaper || DEFAULT_ESCAPER), template) end + private + def self.render_template(params, template) params.inject(template) do | template, (key, value) | template.gsub("${#{key}}", value) diff --git a/lib/pact_broker/webhooks/webhook_request_template.rb b/lib/pact_broker/webhooks/webhook_request_template.rb index c64a54383..786a1eebb 100644 --- a/lib/pact_broker/webhooks/webhook_request_template.rb +++ b/lib/pact_broker/webhooks/webhook_request_template.rb @@ -44,7 +44,7 @@ def build(template_params) end def description - "#{http_method.upcase} #{URI(url.gsub(PactBroker::Webhooks::Render::TEMPLATE_PARAMETER_REGEXP, 'placeholder')).host}" + "#{http_method.upcase} #{URI(PactBroker::Webhooks::Render.render_with_placeholder(url)).host}" end def display_password