Skip to content

Commit

Permalink
Use issue class
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatol Broder committed Aug 17, 2014
1 parent c139062 commit d3761cf
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/html/proofer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require 'nokogiri'
require 'yell'

require File.dirname(__FILE__) + '/proofer/checkable'
require File.dirname(__FILE__) + '/proofer/checks'
[
'checkable',
'checks',
'issue'
].each { |r| require File.join(File.dirname(__FILE__), "proofer", r) }

module HTML
class Proofer
Expand Down Expand Up @@ -62,7 +65,7 @@ def run
if @failed_tests.empty?
logger.info colorize :green, "HTML-Proofer finished successfully."
else
@failed_tests.sort.each do |issue|
@failed_tests.sort_by(&:path).each do |issue|
logger.error colorize :red, issue.to_s
end

Expand Down Expand Up @@ -112,9 +115,7 @@ def response_handler(response, filenames)
if response_code.between?(200, 299)
# continue with no op
elsif response.timed_out?
failed_test_msg = "External link #{href} failed: got a time out"
failed_test_msg.insert(0, "#{filenames.join(' ').blue}: ") unless filenames.nil?
@failed_tests << failed_test_msg
add_failed_tests filenames, "External link #{href} failed: got a time out", response_code
elsif (response_code == 405 || response_code == 420 || response_code == 503) && method == :head
# 420s usually come from rate limiting; let's ignore the query and try just the path with a GET
uri = URI(href)
Expand All @@ -125,9 +126,7 @@ def response_handler(response, filenames)
queue_request(:get, href, filenames)
else
# Received a non-successful http response.
failed_test_msg = "External link #{href} failed: #{response_code} #{response.return_message}"
failed_test_msg.insert(0, "#{filenames.join(' ').blue}: ") unless filenames.nil?
@failed_tests << failed_test_msg
add_failed_tests filenames, "External link #{href} failed: #{response_code} #{response.return_message}", response_code
end
end

Expand Down Expand Up @@ -167,6 +166,16 @@ def colorize(color, string)
end
end

def add_failed_tests(filenames, desc, status = nil)
if filenames.nil?
@failed_tests << Checks::Issue.new("", desc, status)
elsif
filenames.each { |f|
@failed_tests << Checks::Issue.new(f, desc, status)
}
end
end

def failed_tests
return [] if @failed_tests.empty?
result = []
Expand Down

0 comments on commit d3761cf

Please sign in to comment.