Skip to content

Commit

Permalink
Revert "Make shield service name dynamic"
Browse files Browse the repository at this point in the history
This reverts commit 381b353.
  • Loading branch information
HazAT committed Jan 8, 2018
1 parent 42474c1 commit 6800622
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
10 changes: 3 additions & 7 deletions lib/badge/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,19 @@ def self.alpha_dark_badge
File.join assets, 'alpha_badge_dark.png'
end

def self.shield_service_name
'shields.io'
end

def self.shield_serveice_base_url
def self.shield_base_url
'https://img.shields.io'
end

def self.shield_path
'/badge/'
end

def self.shield_service_timeout
def self.shield_io_timeout
10
end

def self.shield_service_retries
def self.shield_io_retries
10
end

Expand Down
6 changes: 3 additions & 3 deletions lib/badge/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def self.available_options
optional: true),

FastlaneCore::ConfigItem.new(key: :shield,
description: "Overlay a shield from #{Badge.shield_service_name} on your icon, eg: Version-1.2-green",
description: "Overlay a shield from shields.io on your icon, eg: Version-1.2-green",
optional: true),

FastlaneCore::ConfigItem.new(key: :shield_service_timeout,
description: "The timeout in seconds we should wait the get a response from #{Badge.shield_service_name}",
FastlaneCore::ConfigItem.new(key: :shield_io_timeout,
description: "The timeout in seconds we should wait the get a response from shields.io",
type: Integer,
optional: true),

Expand Down
22 changes: 11 additions & 11 deletions lib/badge/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ def run(path, options)

shield = nil
begin
timeout = Badge.shield_service_timeout
timeout = options[:shield_service_timeout] if options[:shield_service_timeout]
timeout = Badge.shield_io_timeout
timeout = options[:shield_io_timeout] if options[:shield_io_timeout]
Timeout.timeout(timeout.to_i) do
shield = load_shield(options[:shield]) if options[:shield]
end
rescue Timeout::Error
UI.error "Error loading image from #{Badge.shield_service_name} timeout reached. Use --verbose for more info".red
UI.error "Error loading image from shields.io timeout reached. Use --verbose for more info".red
rescue Curl::Err::CurlError => error
response = error.io
UI.error "Error loading image from #{Badge.shield_service_name} response Error. Use --verbose for more info".red
UI.error "Error loading image from shields.io response Error. Use --verbose for more info".red
UI.verbose response.status if FastlaneCore::Globals.verbose?
rescue MiniMagick::Invalid
UI.error "Error validating image from #{Badge.shield_service_name}. Use --verbose for more info".red
UI.error "Error validating image from shields.io. Use --verbose for more info".red
rescue Exception => error
UI.error "Other error occured. Use --verbose for more info".red
UI.verbose error if FastlaneCore::Globals.verbose?
end

if options[:shield] && shield == nil
if @@retry_attemps >= Badge.shield_service_retries
UI.error "Cannot load image from #{Badge.shield_service_name} skipping it...".red
if @@retry_attemps >= Badge.shield_io_retries
UI.error "Cannot load image from shields.io skipping it...".red
else
UI.message "Waiting for #{timeout.to_i}s and retry to load image from #{Badge.shield_service_name} tries remaining: #{Badge.shield_service_retries - @@retry_attemps}".red
UI.message "Waiting for #{timeout.to_i}s and retry to load image from shields.io tries remaining: #{Badge.shield_io_retries - @@retry_attemps}".red
sleep timeout.to_i
@@retry_attemps += 1
return run(path, options)
Expand Down Expand Up @@ -100,7 +100,7 @@ def run(path, options)

def add_shield(icon, result, shield, alpha_channel, shield_gravity, shield_no_resize, shield_scale, shield_geometry)
UI.message "'#{icon.path}'"
UI.verbose "Adding #{Badge.shield_service_name} image ontop of icon".blue
UI.verbose "Adding shields.io image ontop of icon".blue

shield_scale = shield_scale ? shield_scale.to_f : 1.0

Expand All @@ -125,10 +125,10 @@ def add_shield(icon, result, shield, alpha_channel, shield_gravity, shield_no_re
end

def load_shield(shield_string)
url = Badge.shield_serveice_base_url + Badge.shield_path + shield_string + (@@rsvg_enabled ? ".svg" : ".png")
url = Badge.shield_base_url + Badge.shield_path + shield_string + (@@rsvg_enabled ? ".svg" : ".png")
file_name = shield_string + (@@rsvg_enabled ? ".svg" : ".png")

UI.verbose "Trying to load image from #{Badge.shield_service_name}. Timeout: #{Badge.shield_service_timeout}s".blue
UI.verbose "Trying to load image from shields.io. Timeout: #{Badge.shield_io_timeout}s".blue
UI.verbose "URL: #{url}".blue

Curl::Easy.download(url, file_name)
Expand Down

0 comments on commit 6800622

Please sign in to comment.