lib/pact_broker/badges/service.rb in pact_broker-2.79.1 vs lib/pact_broker/badges/service.rb in pact_broker-2.80.0
- old
+ new
@@ -1,12 +1,12 @@
-require 'net/http'
-require 'uri'
-require 'pact_broker/project_root'
-require 'pact_broker/logging'
-require 'pact_broker/configuration'
-require 'pact_broker/build_http_options'
-require 'erb'
+require "net/http"
+require "uri"
+require "pact_broker/project_root"
+require "pact_broker/logging"
+require "pact_broker/configuration"
+require "pact_broker/build_http_options"
+require "erb"
module PactBroker
module Badges
module Service
@@ -49,23 +49,23 @@
end
private
def badge_title pact, label, initials, metadata
- return 'pact not found' if pact.nil?
+ return "pact not found" if pact.nil?
consumer_name = prepare_name(pact.consumer_name, initials, metadata[:consumer_tag])
provider_name = prepare_name(pact.provider_name, initials, metadata[:provider_tag])
- title = case (label || '').downcase
- when 'consumer' then consumer_name
- when 'provider' then provider_name
+ title = case (label || "").downcase
+ when "consumer" then consumer_name
+ when "provider" then provider_name
else "#{consumer_name}/#{provider_name}"
- end
+ end
"#{title} pact".downcase
end
def prepare_name name, initials, tag = nil
- tag_suffix = tag ? " (#{tag})" : ''
+ tag_suffix = tag ? " (#{tag})" : ""
if initials
parts = split_space_dash_underscore(name)
parts = split_camel_case(name) if parts.size == 1
return parts.collect{ |p| p[0] }.join.downcase + tag_suffix if parts.size > 1
end
@@ -77,12 +77,12 @@
end
def split_camel_case name
name.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
- .tr('-', '_')
- .split('_')
+ .tr("-", "_")
+ .split("_")
end
def badge_status pseudo_branch_verification_status
case pseudo_branch_verification_status
when :success then "verified"
@@ -104,11 +104,11 @@
def dynamic_svg pact, label, initials, pseudo_branch_verification_status, metadata
return nil unless PactBroker.configuration.shields_io_base_url
uri = pact_verification_badge_url(pact, label, initials, pseudo_branch_verification_status, metadata)
begin
response = do_request(uri)
- response.code == '200' ? response.body : nil
+ response.code == "200" ? response.body : nil
rescue Net::OpenTimeout => e
logger.warn "Timeout retrieving badge from #{uri} #{e.class} - #{e.message}"
nil
rescue StandardError => e
logger.warn("Error retrieving badge from #{uri}", e)
@@ -139,23 +139,23 @@
end
def with_cache uri
if !(response = CACHE[uri])
response = yield
- if response.code == '200'
+ if response.code == "200"
CACHE[uri] = response
end
end
response
end
def static_svg pact, pseudo_branch_verification_status
file_name = case pseudo_branch_verification_status
- when :success then "pact-verified-brightgreen.svg"
- when :failed then "pact-failed-red.svg"
- when :stale then "pact-changed-orange.svg"
- else "pact-unknown-lightgrey.svg"
- end
+ when :success then "pact-verified-brightgreen.svg"
+ when :failed then "pact-failed-red.svg"
+ when :stale then "pact-changed-orange.svg"
+ else "pact-unknown-lightgrey.svg"
+ end
file_name = "pact_not_found-unknown-lightgrey.svg" unless pact
File.read(PactBroker.project_root.join("public", "images", file_name))
end
end
end