diff --git a/lib/codacy/configuration.rb b/lib/codacy/configuration.rb index db719e2..dda35b2 100644 --- a/lib/codacy/configuration.rb +++ b/lib/codacy/configuration.rb @@ -21,11 +21,19 @@ def self.logger_to_stdout end def self.logger_to_file - log_filename = self.temp_dir + 'codacy-coverage_' + Date.today.to_s + '.log' - log_file = File.open(log_filename, 'a') + log_file_path = self.temp_dir + self.log_file_name + log_file = File.open(log_file_path, 'a') Logger.new(log_file) end + def self.log_file_name + today = Date.today + # rails overrides to_s method of Date class + # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/date/conversions.rb#L52 + timestamp = today.respond_to?(:to_default_s) ? today.to_default_s : today.to_s + 'codacy-coverage_' + timestamp + '.log' + end + def self.temp_dir directory_name = Dir.tmpdir + "/codacy-coverage/" Dir.mkdir(directory_name) unless File.exists?(directory_name) diff --git a/lib/codacy/git.rb b/lib/codacy/git.rb index a71af0e..1467d2c 100644 --- a/lib/codacy/git.rb +++ b/lib/codacy/git.rb @@ -13,6 +13,11 @@ def self.commit_id commit end + def self.work_dir + work_dir = ENV['WORK_DIR'] || git_dir + work_dir + end + def self.git_commit git("log -1 --pretty=format:'%H'") end diff --git a/lib/codacy/parser.rb b/lib/codacy/parser.rb index 0952a9d..dcea203 100644 --- a/lib/codacy/parser.rb +++ b/lib/codacy/parser.rb @@ -2,7 +2,7 @@ module Codacy module Parser def self.parse_file(simplecov_result) - project_dir = Codacy::Git.git_dir + project_dir = Codacy::Git.work_dir logger.info("Parsing simplecov result to Codacy format...") logger.debug(simplecov_result.original_result) @@ -36,4 +36,4 @@ def self.logger Codacy::Configuration.logger end end -end \ No newline at end of file +end