Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Commit 7e88ca3

Browse files
authored
Merge pull request #19 from arthurhuangzh/ar-fix-log-file-name-bug
Fix cannot open log file when run with Rails project
2 parents 6052523 + 89c0421 commit 7e88ca3

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

lib/codacy/configuration.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ def self.logger_to_stdout
2121
end
2222

2323
def self.logger_to_file
24-
log_filename = self.temp_dir + 'codacy-coverage_' + Date.today.to_s + '.log'
25-
log_file = File.open(log_filename, 'a')
24+
log_file_path = self.temp_dir + self.log_file_name
25+
log_file = File.open(log_file_path, 'a')
2626
Logger.new(log_file)
2727
end
2828

29+
def self.log_file_name
30+
today = Date.today
31+
# rails overrides to_s method of Date class
32+
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/date/conversions.rb#L52
33+
timestamp = today.respond_to?(:to_default_s) ? today.to_default_s : today.to_s
34+
'codacy-coverage_' + timestamp + '.log'
35+
end
36+
2937
def self.temp_dir
3038
directory_name = Dir.tmpdir + "/codacy-coverage/"
3139
Dir.mkdir(directory_name) unless File.exists?(directory_name)

lib/codacy/git.rb

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ def self.commit_id
1313
commit
1414
end
1515

16+
def self.work_dir
17+
work_dir = ENV['WORK_DIR'] || git_dir
18+
work_dir
19+
end
20+
1621
def self.git_commit
1722
git("log -1 --pretty=format:'%H'")
1823
end

lib/codacy/parser.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Codacy
22
module Parser
33

44
def self.parse_file(simplecov_result)
5-
project_dir = Codacy::Git.git_dir
5+
project_dir = Codacy::Git.work_dir
66

77
logger.info("Parsing simplecov result to Codacy format...")
88
logger.debug(simplecov_result.original_result)
@@ -36,4 +36,4 @@ def self.logger
3636
Codacy::Configuration.logger
3737
end
3838
end
39-
end
39+
end

0 commit comments

Comments
 (0)