class Codecov::SimpleCov::Formatter
def file_network
def file_network invalid_file_types = [ 'woff', 'eot', 'otf', # fonts 'gif', 'png', 'jpg', 'jpeg', 'psd', # images 'ptt', 'pptx', 'numbers', 'pages', 'md', 'txt', 'xlsx', 'docx', 'doc', 'pdf', 'csv', # docs 'yml', 'yaml', '.gitignore' ].freeze invalid_directories = [ 'node_modules/', 'storage/', 'tmp/', 'vendor/' ] network = [] Dir['**/*'].keep_if do |file| if File.file?(file) && !file.end_with?(*invalid_file_types) && invalid_directories.none? { |dir| file.include?(dir) } network.push(file) end end network.push('<<<<<< network') network end
def file_to_codecov(file)
-
(Array
-)
Parameters:
-
file
(SimpleCov::SourceFile
) -- The file to process.
def file_to_codecov(file) # Initial nil is required to offset line numbers. [nil] + file.lines.map do |line| if line.skipped? nil else line.coverage end end end
def format(report)
def format(report) result = { 'meta' => { 'version' => "codecov-ruby/v#{::Codecov::VERSION}" } } result.update(result_to_codecov(report)) begin result_path = File.join(::SimpleCov.coverage_path, RESULT_FILE_NAME) File.write(result_path, result['codecov']) overflow = result['coverage'].to_s.length > 256 ? '...' : '' puts "Coverage report generated to #{result_path}.\n#{result['coverage'].to_s.[](0, 255)}#{overflow}" rescue Errno::ENOENT => e puts e puts "Could not write coverage report to file.\n#{result}" end result end
def result_to_codecov(result)
-
(Hash)
-
Parameters:
-
result
(SimpleCov::Result
) -- The coverage data to process.
def result_to_codecov(result) { 'codecov' => result_to_codecov_report(result), 'coverage' => result_to_codecov_coverage(result), 'messages' => result_to_codecov_messages(result) } end
def result_to_codecov_coverage(result)
-
(Hash
-)
Parameters:
-
result
(SimpleCov::Result
) -- The coverage data to process.
def result_to_codecov_coverage(result) result.files.each_with_object({}) do |file, memo| memo[shortened_filename(file)] = file_to_codecov(file) end end
def result_to_codecov_messages(result)
-
(Hash
-)
Parameters:
-
result
(SimpleCov::Result
) -- The coverage data to process.
def result_to_codecov_messages(result) result.files.each_with_object({}) do |file, memo| memo[shortened_filename(file)] = file.lines.each_with_object({}) do |line, lines_memo| lines_memo[line.line_number.to_s] = 'skipped' if line.skipped? end end end
def result_to_codecov_report(result)
def result_to_codecov_report(result) report = file_network.join("\n").concat("\n") report.concat({ 'coverage' => result_to_codecov_coverage(result) }.to_json) end
def shortened_filename(file)
-
(String)
-
Parameters:
-
file
(SimpleCov::SourceFile
) -- The file to use.
def shortened_filename(file) file.filename.gsub(/^#{::SimpleCov.root}/, '.').gsub(%r{^\./}, '') end