Sha256: a100a519a44e99dfe71271bbcdd4cbebeacfda08fa797f5cd6f6689197600287

Contents?: true

Size: 1.37 KB

Versions: 473

Compression:

Stored size: 1.37 KB

Contents

require 'addressable'
require 'faraday_middleware'

require_relative '../rule'

module Precheck
  class UnreachableURLRule < URLRule
    def self.key
      :unreachable_urls
    end

    def self.env_name
      "RULE_UNREACHABLE_URLS"
    end

    def self.friendly_name
      "No broken urls"
    end

    def self.description
      "unreachable URLs in app metadata"
    end

    def rule_block
      return lambda { |url|
        url = url.to_s.strip
        return RuleReturn.new(validation_state: Precheck::VALIDATION_STATES[:failed], failure_data: "empty url") if url.empty?

        begin
          uri = Addressable::URI.parse(url)
          uri.fragment = nil
          request = Faraday.new(uri.normalize.to_s) do |connection|
            connection.use(FaradayMiddleware::FollowRedirects)
            connection.adapter(:net_http)
          end
          return RuleReturn.new(validation_state: Precheck::VALIDATION_STATES[:failed], failure_data: url) unless request.head.status == 200
        rescue StandardError => e
          UI.verbose("URL #{url} not reachable 😵: #{e.message}")
          # I can only return :fail here, but I also want to return #{url}
          return RuleReturn.new(validation_state: VALIDATION_STATES[:failed], failure_data: "unreachable: #{url}")
        end

        return RuleReturn.new(validation_state: VALIDATION_STATES[:passed])
      }
    end
  end
end

Version data entries

473 entries across 473 versions & 4 rubygems

Version Path
fastlane-2.132.0.beta.20190927200017 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190926200023 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190925200108 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190924200030 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190923200017 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190922200014 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190921200021 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190920200012 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190919200100 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190918200023 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190917200011 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190916200055 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190915200038 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190914200034 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190913200058 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.132.0.beta.20190912200052 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.131.0 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.131.0.beta.20190911200010 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.131.0.beta.20190910200104 precheck/lib/precheck/rules/unreachable_urls_rule.rb
fastlane-2.131.0.beta.20190909200058 precheck/lib/precheck/rules/unreachable_urls_rule.rb