Skip to content

Commit

Permalink
refactor start script and add option for custom coverage result path
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Reinert committed Nov 30, 2016
1 parent f68b7bb commit cb6a305
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions bin/codeclimate-test-reporter
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

require "codeclimate-test-reporter"

COVERAGE_FILE = "coverage/.resultset.json".freeze
repo_token = ENV["CODECLIMATE_REPO_TOKEN"]
if repo_token.nil? || repo_token.empty?
STDERR.puts "Cannot post results: environment variable CODECLIMATE_REPO_TOKEN must be set."
exit
end

COVERAGE_FILE = ARGV.first || "coverage/.resultset.json"

if (repo_token = ENV["CODECLIMATE_REPO_TOKEN"]) && !repo_token.empty?
if File.exist?(COVERAGE_FILE)
begin
results = JSON.parse(File.read(COVERAGE_FILE))
rescue JSON::ParserError => e
$stderr.puts "Error encountered while parsing #{COVERAGE_FILE}: #{e}"
exit(1)
end
abort "Coverage results not found" unless File.exist?(COVERAGE_FILE)

CodeClimate::TestReporter.run(results)
else
$stderr.puts "Coverage results not found"
exit(1)
end
else
$stderr.puts "Cannot post results: environment variable CODECLIMATE_REPO_TOKEN must be set."
exit(0)
begin
results = JSON.parse(File.read(COVERAGE_FILE))
rescue JSON::ParserError => e
abort "Error encountered while parsing #{COVERAGE_FILE}: #{e}"
end

CodeClimate::TestReporter.run(results)

0 comments on commit cb6a305

Please sign in to comment.