danger-jacoco-instacart 0.1.11 → 0.1.12.SNAPSHOT.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardoc/checksums +2 -2
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/lib/jacoco/gem_version.rb +1 -1
- data/lib/jacoco/plugin.rb +47 -14
- data/spec/jacoco_spec.rb +48 -19
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b68f00cbed8e16eb566459431cfb6d296b84b2fec8b87f5e07cb40e513b08b1c
|
4
|
+
data.tar.gz: a14e683220953972e2ee3fa84ff6f4fd795c60701c8108d187a24f710b10eced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a8ed5dfd7cf494b6e1ceb45f87d06d8666e6f92ec1e31b73a75bdf00a2cc209c67854d3d0eee1eb367b4311ac280a22115fb075d904538f611ccb44ac94d5e7
|
7
|
+
data.tar.gz: 6c2cc47baf7fea31de40f60b531a442a5daad3460b2ecf6360dc6e1860077a4888fff6e9e071c0d4775c87224533e66edf1483586418220953762ed76621399a
|
data/.yardoc/checksums
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/danger_jacoco.rb 38229d934b3315bb2a5a4eec18eb65f3c54d304f
|
2
|
-
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/gem_version.rb
|
3
|
-
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/plugin.rb
|
2
|
+
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/gem_version.rb 4109fe221b49a7d872a2d1bebf772583ed7c4437
|
3
|
+
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/plugin.rb 17233d007f6187a47676390d6499ab5c7cb3a2b8
|
4
4
|
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/sax_parser.rb 370e2799f8dbdf7d642c820214e6ea84c30c9cb0
|
5
5
|
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/model/counter.rb 368f4a9811617b7a174ddf837a8fac49a4bc32a6
|
6
6
|
/Users/alexanderbezverhni/workspace/junk/danger-jacoco/lib/jacoco/model/report.rb 7cf45ee71ff347a130320f6190ddb25525c7095d
|
data/.yardoc/object_types
CHANGED
Binary file
|
data/.yardoc/objects/root.dat
CHANGED
Binary file
|
data/lib/jacoco/gem_version.rb
CHANGED
data/lib/jacoco/plugin.rb
CHANGED
@@ -20,9 +20,10 @@ module Danger
|
|
20
20
|
# @tags jacoco, coverage, java, android, kotlin
|
21
21
|
#
|
22
22
|
class DangerJacoco < Plugin # rubocop:disable Metrics/ClassLength
|
23
|
-
attr_accessor :minimum_project_coverage_percentage, :minimum_class_coverage_percentage,
|
24
|
-
:
|
25
|
-
:
|
23
|
+
attr_accessor :minimum_project_coverage_percentage, :minimum_class_coverage_percentage,
|
24
|
+
:minimum_composable_class_coverage_percentage, :only_check_new_files, :files_extension,
|
25
|
+
:minimum_package_coverage_map, :minimum_class_coverage_map, :fail_no_coverage_data_found,
|
26
|
+
:title, :class_column_title, :subtitle_success, :subtitle_failure
|
26
27
|
|
27
28
|
# Initialize the plugin with configured parameters or defaults
|
28
29
|
def setup
|
@@ -44,6 +45,7 @@ module Danger
|
|
44
45
|
def setup_minimum_coverages
|
45
46
|
@minimum_project_coverage_percentage = 0 unless minimum_project_coverage_percentage
|
46
47
|
@minimum_class_coverage_percentage = 0 unless minimum_class_coverage_percentage
|
48
|
+
@minimum_composable_class_coverage_percentage = 0 unless minimum_composable_class_coverage_percentage
|
47
49
|
@minimum_package_coverage_map = {} unless minimum_package_coverage_map
|
48
50
|
@minimum_class_coverage_map = {} unless minimum_class_coverage_map
|
49
51
|
end
|
@@ -79,9 +81,10 @@ module Danger
|
|
79
81
|
@fail_no_coverage_data_found = fail_no_coverage_data_found
|
80
82
|
|
81
83
|
setup
|
82
|
-
|
84
|
+
class_to_file_path_hash = classes(delimiter)
|
85
|
+
classnames = class_to_file_path_hash.keys
|
83
86
|
|
84
|
-
parser = Jacoco::SAXParser.new(
|
87
|
+
parser = Jacoco::SAXParser.new(classnames)
|
85
88
|
Nokogiri::XML::SAX::Parser.new(parser).parse(File.open(path))
|
86
89
|
|
87
90
|
total_covered = total_coverage(path)
|
@@ -90,7 +93,7 @@ module Danger
|
|
90
93
|
report_markdown = header
|
91
94
|
report_markdown += "| #{class_column_title} | Covered | Required | Status |\n"
|
92
95
|
report_markdown += "|:---|:---:|:---:|:---:|\n"
|
93
|
-
class_coverage_above_minimum = markdown_class(parser, report_markdown, report_url)
|
96
|
+
class_coverage_above_minimum = markdown_class(parser, report_markdown, report_url, class_to_file_path_hash)
|
94
97
|
subtitle = class_coverage_above_minimum ? subtitle_success : subtitle_failure
|
95
98
|
report_markdown.insert(header.length, "#### #{subtitle}\n")
|
96
99
|
markdown(report_markdown)
|
@@ -104,12 +107,17 @@ module Danger
|
|
104
107
|
def classes(delimiter)
|
105
108
|
git = @dangerfile.git
|
106
109
|
affected_files = only_check_new_files ? git.added_files : git.added_files + git.modified_files
|
110
|
+
class_to_file_path_hash = {}
|
107
111
|
affected_files.select { |file| files_extension.reduce(false) { |state, el| state || file.end_with?(el) } }
|
108
|
-
.
|
112
|
+
.each do |file| # "src/java/com/example/CachedRepository.java"
|
113
|
+
classname = file.split('.').first.split(delimiter)[1] # "com/example/CachedRepository"
|
114
|
+
class_to_file_path_hash[classname] = file
|
115
|
+
end
|
116
|
+
class_to_file_path_hash
|
109
117
|
end
|
110
118
|
|
111
119
|
# It returns a specific class code coverage and an emoji status as well
|
112
|
-
def report_class(jacoco_class)
|
120
|
+
def report_class(jacoco_class, file_path)
|
113
121
|
report_result = {
|
114
122
|
covered: 'No coverage data found : -',
|
115
123
|
status: ':black_joker:',
|
@@ -119,7 +127,7 @@ module Danger
|
|
119
127
|
counter = coverage_counter(jacoco_class)
|
120
128
|
unless counter.nil?
|
121
129
|
coverage = (counter.covered.fdiv(counter.covered + counter.missed) * 100).floor
|
122
|
-
required_coverage = required_class_coverage(jacoco_class)
|
130
|
+
required_coverage = required_class_coverage(jacoco_class, file_path)
|
123
131
|
status = coverage_status(coverage, required_coverage)
|
124
132
|
|
125
133
|
report_result = {
|
@@ -133,13 +141,19 @@ module Danger
|
|
133
141
|
end
|
134
142
|
|
135
143
|
# Determines the required coverage for the class
|
136
|
-
|
144
|
+
# rubocop:disable Metrics/AbcSize
|
145
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
146
|
+
def required_class_coverage(jacoco_class, file_path)
|
137
147
|
key = minimum_class_coverage_map.keys.detect { |k| jacoco_class.name.match(k) } || jacoco_class.name
|
138
148
|
required_coverage = minimum_class_coverage_map[key]
|
149
|
+
includes_composables = File.read(file_path).include? '@Composable' if File.exist?(file_path)
|
150
|
+
required_coverage = minimum_composable_class_coverage_percentage if required_coverage.nil? && includes_composables
|
139
151
|
required_coverage = package_coverage(jacoco_class.name) if required_coverage.nil?
|
140
152
|
required_coverage = minimum_class_coverage_percentage if required_coverage.nil?
|
141
153
|
required_coverage
|
142
154
|
end
|
155
|
+
# rubocop:enable Metrics/AbcSize
|
156
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
143
157
|
|
144
158
|
# it returns the most suitable coverage by package name to class or nil
|
145
159
|
def package_coverage(class_name)
|
@@ -213,22 +227,34 @@ module Danger
|
|
213
227
|
|
214
228
|
# rubocop:disable Style/SignalException
|
215
229
|
def report_fails(class_coverage_above_minimum, total_covered)
|
230
|
+
total_failure_message = ''
|
216
231
|
if total_covered[:covered] < minimum_project_coverage_percentage
|
217
232
|
# fail danger if total coverage is smaller than minimum_project_coverage_percentage
|
218
233
|
covered = total_covered[:covered]
|
219
|
-
|
234
|
+
total_failure_message = "Total coverage of #{covered}%." \
|
235
|
+
" Improve this to at least #{minimum_project_coverage_percentage}%"
|
236
|
+
fail(total_failure_message)
|
237
|
+
# rubocop:disable Lint/UnreachableCode (rubocop mistakenly thinks that raise is unreachable since priorly called "fail" raises by itself, but in fact "fail" is caught and handled)
|
238
|
+
raise CoverageRequirementsNotMetError, total_failure_message if class_coverage_above_minimum
|
239
|
+
# rubocop:enable Lint/UnreachableCode
|
220
240
|
end
|
221
241
|
|
222
242
|
return if class_coverage_above_minimum
|
223
243
|
|
224
|
-
|
244
|
+
class_failure_message = 'Class coverage is below minimum.' \
|
245
|
+
" Improve to at least #{minimum_class_coverage_percentage}%"
|
246
|
+
fail(class_failure_message)
|
247
|
+
# rubocop:disable Lint/UnreachableCode (rubocop mistakenly thinks that raise is unreachable since priorly called "fail" raises by itself, but in fact "fail" is caught and handled)
|
248
|
+
raise CoverageRequirementsNotMetError, "#{total_failure_message}. #{class_failure_message}"
|
249
|
+
# rubocop:enable Lint/UnreachableCode
|
225
250
|
end
|
226
251
|
# rubocop:enable Style/SignalException
|
227
252
|
|
228
|
-
def markdown_class(parser, report_markdown, report_url)
|
253
|
+
def markdown_class(parser, report_markdown, report_url, class_to_file_path_hash)
|
229
254
|
class_coverage_above_minimum = true
|
230
255
|
parser.classes.each do |jacoco_class| # Check metrics for each classes
|
231
|
-
|
256
|
+
file_path = class_to_file_path_hash[jacoco_class.name]
|
257
|
+
rp = report_class(jacoco_class, file_path)
|
232
258
|
rl = report_link(jacoco_class.name, report_url)
|
233
259
|
ln = "| #{rl} | #{rp[:covered]}% | #{rp[:required_coverage_percentage]}% | #{rp[:status]} |\n"
|
234
260
|
report_markdown << ln
|
@@ -249,3 +275,10 @@ module Danger
|
|
249
275
|
end
|
250
276
|
end
|
251
277
|
end
|
278
|
+
|
279
|
+
# Exception that is being thrown when any of the coverage requirements aren't met
|
280
|
+
class CoverageRequirementsNotMetError < StandardError
|
281
|
+
def initialize(msg = 'Coverage requirements not met')
|
282
|
+
super
|
283
|
+
end
|
284
|
+
end
|
data/spec/jacoco_spec.rb
CHANGED
@@ -33,7 +33,7 @@ module Danger
|
|
33
33
|
@my_plugin.minimum_project_coverage_percentage = 50
|
34
34
|
@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 100 }
|
35
35
|
|
36
|
-
@my_plugin.report
|
36
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%. Class coverage is below minimum. Improve to at least 0%/)
|
37
37
|
|
38
38
|
expect(@dangerfile.status_report[:errors]).to eq(['Total coverage of 32.9%. Improve this to at least 50%',
|
39
39
|
'Class coverage is below minimum. Improve to at least 0%'])
|
@@ -49,8 +49,7 @@ module Danger
|
|
49
49
|
@my_plugin.minimum_project_coverage_percentage = 50
|
50
50
|
@my_plugin.minimum_class_coverage_map = { '.*Repository' => 60 }
|
51
51
|
|
52
|
-
@my_plugin.report
|
53
|
-
|
52
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%. Class coverage is below minimum. Improve to at least 0%/)
|
54
53
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 60% | :warning: |')
|
55
54
|
end
|
56
55
|
|
@@ -60,8 +59,7 @@ module Danger
|
|
60
59
|
@my_plugin.minimum_project_coverage_percentage = 50
|
61
60
|
@my_plugin.minimum_package_coverage_map = { 'com/example/' => 70 }
|
62
61
|
|
63
|
-
@my_plugin.report
|
64
|
-
|
62
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
|
65
63
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
|
66
64
|
end
|
67
65
|
|
@@ -74,8 +72,7 @@ module Danger
|
|
74
72
|
'com/' => 90
|
75
73
|
}
|
76
74
|
|
77
|
-
@my_plugin.report
|
78
|
-
|
75
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
|
79
76
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
|
80
77
|
end
|
81
78
|
|
@@ -88,8 +85,7 @@ module Danger
|
|
88
85
|
'com/' => 30
|
89
86
|
}
|
90
87
|
|
91
|
-
@my_plugin.report
|
92
|
-
|
88
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
|
93
89
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 77% | :warning: |')
|
94
90
|
end
|
95
91
|
|
@@ -103,8 +99,7 @@ module Danger
|
|
103
99
|
}
|
104
100
|
@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 100 }
|
105
101
|
|
106
|
-
@my_plugin.report
|
107
|
-
|
102
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
|
108
103
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 100% | :warning: |')
|
109
104
|
end
|
110
105
|
|
@@ -118,8 +113,7 @@ module Danger
|
|
118
113
|
}
|
119
114
|
@my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 80 }
|
120
115
|
|
121
|
-
@my_plugin.report
|
122
|
-
|
116
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%/)
|
123
117
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 80% | :warning: |')
|
124
118
|
end
|
125
119
|
|
@@ -156,7 +150,7 @@ module Danger
|
|
156
150
|
@my_plugin.minimum_class_coverage_percentage = 70
|
157
151
|
@my_plugin.only_check_new_files = true
|
158
152
|
|
159
|
-
@my_plugin.report
|
153
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 70%/)
|
160
154
|
|
161
155
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('### JaCoCo Code Coverage 55.59% :white_check_mark:')
|
162
156
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| Class | Covered | Required | Status |')
|
@@ -171,8 +165,7 @@ module Danger
|
|
171
165
|
@my_plugin.minimum_class_coverage_percentage = 80
|
172
166
|
@my_plugin.minimum_project_coverage_percentage = 50
|
173
167
|
|
174
|
-
@my_plugin.report(path_a, 'http://test.com/')
|
175
|
-
|
168
|
+
expect { @my_plugin.report(path_a, 'http://test.com/') }.to raise_error(CoverageRequirementsNotMetError, /Total coverage of 32.9%. Improve this to at least 50%. Class coverage is below minimum. Improve to at least 80%/)
|
176
169
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| [`com/example/CachedRepository`](http://test.com/com.example/CachedRepository.html) | 50% | 80% | :warning: |')
|
177
170
|
end
|
178
171
|
|
@@ -234,7 +227,7 @@ module Danger
|
|
234
227
|
@my_plugin.minimum_project_coverage_percentage = 30
|
235
228
|
@my_plugin.minimum_class_coverage_percentage = 60
|
236
229
|
|
237
|
-
@my_plugin.report
|
230
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 60%/)
|
238
231
|
|
239
232
|
expected = "### JaCoCo Code Coverage 32.9% :white_check_mark:\n"
|
240
233
|
expected += "#### There are classes that do not meet coverage requirement :warning:\n"
|
@@ -268,7 +261,7 @@ module Danger
|
|
268
261
|
@my_plugin.minimum_class_coverage_percentage = 60
|
269
262
|
@my_plugin.subtitle_failure = 'Too bad :('
|
270
263
|
|
271
|
-
@my_plugin.report
|
264
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 60%/)
|
272
265
|
|
273
266
|
expected = "### JaCoCo Code Coverage 32.9% :white_check_mark:\n"
|
274
267
|
expected += "#### Too bad :(\n"
|
@@ -311,7 +304,7 @@ module Danger
|
|
311
304
|
|
312
305
|
@my_plugin.minimum_class_coverage_percentage = 50
|
313
306
|
|
314
|
-
@my_plugin.report
|
307
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 50%/)
|
315
308
|
|
316
309
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 42% | 50% | :warning: |')
|
317
310
|
end
|
@@ -325,6 +318,42 @@ module Danger
|
|
325
318
|
|
326
319
|
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 93% | 50% | :white_check_mark: |')
|
327
320
|
end
|
321
|
+
|
322
|
+
describe 'with CachedRepository containing @Composable annotation' do
|
323
|
+
before do
|
324
|
+
allow(File).to receive(:exist?).with('src/java/com/example/CachedRepository.java').and_return(true)
|
325
|
+
allow(File).to receive(:read).with('src/java/com/example/CachedRepository.java').and_return('package com.kevin.mia.mikaela class Vika { @Composable fun someUiWidget() {} }')
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'applies minimum_composable_class_coverage_percentage' do
|
329
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
330
|
+
|
331
|
+
@my_plugin.minimum_class_coverage_percentage = 55
|
332
|
+
@my_plugin.minimum_composable_class_coverage_percentage = 45
|
333
|
+
|
334
|
+
@my_plugin.report path_a
|
335
|
+
|
336
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 45% | :white_check_mark: |')
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
describe 'with CachedRepository _not_ containing @Composable annotation' do
|
341
|
+
before do
|
342
|
+
allow(File).to receive(:exist?).with('src/java/com/example/CachedRepository.java').and_return(true)
|
343
|
+
allow(File).to receive(:read).with('src/java/com/example/CachedRepository.java').and_return('package com.kevin.mia.mikaela class Vika { fun main() {} }')
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'does not apply minimum_composable_class_coverage_percentage' do
|
347
|
+
path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
|
348
|
+
|
349
|
+
@my_plugin.minimum_class_coverage_percentage = 55
|
350
|
+
@my_plugin.minimum_composable_class_coverage_percentage = 45
|
351
|
+
|
352
|
+
expect { @my_plugin.report(path_a) }.to raise_error(CoverageRequirementsNotMetError, /Class coverage is below minimum. Improve to at least 55%/)
|
353
|
+
|
354
|
+
expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 55% | :warning: |')
|
355
|
+
end
|
356
|
+
end
|
328
357
|
end
|
329
358
|
end
|
330
359
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-jacoco-instacart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12.SNAPSHOT.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Malinskiy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-08
|
12
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: danger-plugin-api
|
@@ -228,9 +228,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
228
228
|
version: '2.6'
|
229
229
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
230
230
|
requirements:
|
231
|
-
- - "
|
231
|
+
- - ">"
|
232
232
|
- !ruby/object:Gem::Version
|
233
|
-
version:
|
233
|
+
version: 1.3.1
|
234
234
|
requirements: []
|
235
235
|
rubygems_version: 3.1.2
|
236
236
|
signing_key:
|