codecov 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28cb9ca7e98d8d586f0c8118cc099def187c61c2cd1bc36882dd835959030404
4
- data.tar.gz: 2ae5223947def7a015e0b92fb591f1090cb086406d7f44e284a241a022a54fa4
3
+ metadata.gz: 7e4bfdd1a36904d0b501d1e6ad97d5242e4a5ffa17a13b1c2968a8346bc26396
4
+ data.tar.gz: f0ee40b20016417dafc3aa0d68685872bd4ad2a6795cee3233b04f4de1ea3fec
5
5
  SHA512:
6
- metadata.gz: f43851f9d6c5b8603bea783df5f52dfc40cc5290dfeb741cee23639bd00a60ab1916b73001f7b17652b11839f995b8bc963b151a71e4a7615510f1f129fe6d28
7
- data.tar.gz: '082f364e342d308a06b25c7955949e225bc8c93d730cbb86d1542c881175441740ffd802e070c071a65f45a8e5df4a536fd4811ef0fc18d732d9e04a8dc046bb'
6
+ metadata.gz: 4e669367d900a5b432fb511986f6e9276df0594378347de38d1a9462f344262fcc28f33333dfec8475afc68888811507cfb3db56398cea78bd28e0f557bbeddd
7
+ data.tar.gz: 1ff31b938ed8383c7dc6c067f607283d9d9aafe468302aef8957eb0ba64148c2361feb4b9c5e2129bf529987f09399c020288b542ca5741f8956948d358fcc27
@@ -11,7 +11,7 @@ require_relative 'codecov/uploader'
11
11
 
12
12
  class SimpleCov::Formatter::Codecov
13
13
  def format(result, disable_net_blockers = true)
14
- report = Codecov::SimpleCov::Formatter.format(result)
14
+ report = Codecov::SimpleCov::Formatter.new.format(result)
15
15
  Codecov::Uploader.upload(report, disable_net_blockers)
16
16
  end
17
17
  end
@@ -4,122 +4,121 @@ require 'simplecov'
4
4
 
5
5
  require_relative 'version'
6
6
 
7
- module Codecov::SimpleCov
8
- class Formatter
9
- def self.format(report)
10
- result = {
11
- 'meta' => {
12
- 'version' => "codecov-ruby/v#{::Codecov::VERSION}"
7
+ module Codecov
8
+ module SimpleCov
9
+ class Formatter
10
+ RESULT_FILE_NAME = 'codecov-result.json'
11
+
12
+ def format(report)
13
+ result = {
14
+ 'meta' => {
15
+ 'version' => "codecov-ruby/v#{::Codecov::VERSION}"
16
+ }
13
17
  }
14
- }
15
- result.update(result_to_codecov(report))
16
- result
17
- end
18
-
19
- private
20
-
21
- # Format SimpleCov coverage data for the Codecov.io API.
22
- #
23
- # @param result [SimpleCov::Result] The coverage data to process.
24
- # @return [Hash]
25
- def self.result_to_codecov(result)
26
- {
27
- 'codecov' => result_to_codecov_report(result),
28
- 'coverage' => result_to_codecov_coverage(result),
29
- 'messages' => result_to_codecov_messages(result)
30
- }
31
- end
18
+ result.update(result_to_codecov(report))
32
19
 
33
- def self.result_to_codecov_report(result)
34
- report = file_network.join("\n").concat("\n")
35
- report.concat({ 'coverage' => result_to_codecov_coverage(result) }.to_json)
36
- end
37
-
38
- def self.file_network
39
- invalid_file_types = [
40
- 'woff', 'eot', 'otf', # fonts
41
- 'gif', 'png', 'jpg', 'jpeg', 'psd', # images
42
- 'ptt', 'pptx', 'numbers', 'pages', 'md', 'txt', 'xlsx', 'docx', 'doc', 'pdf', 'csv', # docs
43
- 'yml', 'yaml', '.gitignore'
44
- ].freeze
45
-
46
- invalid_directories = [
47
- 'node_modules/',
48
- 'public/',
49
- 'storage/',
50
- 'tmp/',
51
- 'vendor/'
52
- ]
53
-
54
- puts [green('==>'), 'Appending file network'].join(' ')
55
- network = []
56
- Dir['**/*'].keep_if do |file|
57
- if File.file?(file) && !file.end_with?(*invalid_file_types) && invalid_directories.none? { |dir| file.include?(dir) }
58
- network.push(file)
20
+ result_path = File.join(::SimpleCov.coverage_path, RESULT_FILE_NAME)
21
+ if File.writable?(result_path)
22
+ File.write(result_path, result['codecov'])
23
+ puts "Coverage report generated to #{result_path}.\#{result}"
24
+ else
25
+ puts "Could not write coverage report to file #{result_path}.\n#{result}"
59
26
  end
27
+
28
+ result
60
29
  end
61
30
 
62
- network.push('<<<<<< network')
63
- network
64
- end
31
+ private
32
+
33
+ # Format SimpleCov coverage data for the Codecov.io API.
34
+ #
35
+ # @param result [SimpleCov::Result] The coverage data to process.
36
+ # @return [Hash]
37
+ def result_to_codecov(result)
38
+ {
39
+ 'codecov' => result_to_codecov_report(result),
40
+ 'coverage' => result_to_codecov_coverage(result),
41
+ 'messages' => result_to_codecov_messages(result)
42
+ }
43
+ end
65
44
 
66
- # Format SimpleCov coverage data for the Codecov.io coverage API.
67
- #
68
- # @param result [SimpleCov::Result] The coverage data to process.
69
- # @return [Hash<String, Array>]
70
- def self.result_to_codecov_coverage(result)
71
- result.files.each_with_object({}) do |file, memo|
72
- memo[shortened_filename(file)] = file_to_codecov(file)
45
+ def result_to_codecov_report(result)
46
+ report = file_network.join("\n").concat("\n")
47
+ report.concat({ 'coverage' => result_to_codecov_coverage(result) }.to_json)
73
48
  end
74
- end
75
49
 
76
- # Format SimpleCov coverage data for the Codecov.io messages API.
77
- #
78
- # @param result [SimpleCov::Result] The coverage data to process.
79
- # @return [Hash<String, Hash>]
80
- def self.result_to_codecov_messages(result)
81
- result.files.each_with_object({}) do |file, memo|
82
- memo[shortened_filename(file)] = file.lines.each_with_object({}) do |line, lines_memo|
83
- lines_memo[line.line_number.to_s] = 'skipped' if line.skipped?
50
+ def file_network
51
+ invalid_file_types = [
52
+ 'woff', 'eot', 'otf', # fonts
53
+ 'gif', 'png', 'jpg', 'jpeg', 'psd', # images
54
+ 'ptt', 'pptx', 'numbers', 'pages', 'md', 'txt', 'xlsx', 'docx', 'doc', 'pdf', 'csv', # docs
55
+ 'yml', 'yaml', '.gitignore'
56
+ ].freeze
57
+
58
+ invalid_directories = [
59
+ 'node_modules/',
60
+ 'public/',
61
+ 'storage/',
62
+ 'tmp/',
63
+ 'vendor/'
64
+ ]
65
+
66
+ network = []
67
+ Dir['**/*'].keep_if do |file|
68
+ if File.file?(file) && !file.end_with?(*invalid_file_types) && invalid_directories.none? { |dir| file.include?(dir) }
69
+ network.push(file)
70
+ end
84
71
  end
72
+
73
+ network.push('<<<<<< network')
74
+ network
85
75
  end
86
- end
87
76
 
88
- # Format coverage data for a single file for the Codecov.io API.
89
- #
90
- # @param file [SimpleCov::SourceFile] The file to process.
91
- # @return [Array<nil, Integer>]
92
- def self.file_to_codecov(file)
93
- # Initial nil is required to offset line numbers.
94
- [nil] + file.lines.map do |line|
95
- if line.skipped?
96
- nil
97
- else
98
- line.coverage
77
+ # Format SimpleCov coverage data for the Codecov.io coverage API.
78
+ #
79
+ # @param result [SimpleCov::Result] The coverage data to process.
80
+ # @return [Hash<String, Array>]
81
+ def result_to_codecov_coverage(result)
82
+ result.files.each_with_object({}) do |file, memo|
83
+ memo[shortened_filename(file)] = file_to_codecov(file)
99
84
  end
100
85
  end
101
- end
102
86
 
103
- # Get a filename relative to the project root. Based on
104
- # https://github.com/colszowka/simplecov-html, copyright Christoph Olszowka.
105
- #
106
- # @param file [SimpleCov::SourceFile] The file to use.
107
- # @return [String]
108
- def self.shortened_filename(file)
109
- file.filename.gsub(/^#{SimpleCov.root}/, '.').gsub(%r{^\./}, '')
110
- end
111
-
112
- # Convenience color methods
113
- def self.black(str)
114
- str.nil? ? '' : "\e[30m#{str}\e[0m"
115
- end
87
+ # Format SimpleCov coverage data for the Codecov.io messages API.
88
+ #
89
+ # @param result [SimpleCov::Result] The coverage data to process.
90
+ # @return [Hash<String, Hash>]
91
+ def result_to_codecov_messages(result)
92
+ result.files.each_with_object({}) do |file, memo|
93
+ memo[shortened_filename(file)] = file.lines.each_with_object({}) do |line, lines_memo|
94
+ lines_memo[line.line_number.to_s] = 'skipped' if line.skipped?
95
+ end
96
+ end
97
+ end
116
98
 
117
- def self.red(str)
118
- str.nil? ? '' : "\e[31m#{str}\e[0m"
119
- end
99
+ # Format coverage data for a single file for the Codecov.io API.
100
+ #
101
+ # @param file [SimpleCov::SourceFile] The file to process.
102
+ # @return [Array<nil, Integer>]
103
+ def file_to_codecov(file)
104
+ # Initial nil is required to offset line numbers.
105
+ [nil] + file.lines.map do |line|
106
+ if line.skipped?
107
+ nil
108
+ else
109
+ line.coverage
110
+ end
111
+ end
112
+ end
120
113
 
121
- def self.green(str)
122
- str.nil? ? '' : "\e[32m#{str}\e[0m"
114
+ # Get a filename relative to the project root. Based on
115
+ # https://github.com/colszowka/simplecov-html, copyright Christoph Olszowka.
116
+ #
117
+ # @param file [SimpleCov::SourceFile] The file to use.
118
+ # @return [String]
119
+ def shortened_filename(file)
120
+ file.filename.gsub(/^#{::SimpleCov.root}/, '.').gsub(%r{^\./}, '')
121
+ end
123
122
  end
124
123
  end
125
124
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Codecov
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codecov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Peak
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-25 00:00:00.000000000 Z
12
+ date: 2021-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simplecov