danger-jacoco 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -0
- data/Gemfile.lock +7 -7
- data/README.md +3 -1
- data/lib/jacoco/gem_version.rb +1 -1
- data/lib/jacoco/plugin.rb +70 -23
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8caafe32ed85b587ff05493d8787e293aaad3eb
|
4
|
+
data.tar.gz: fded83a5dbdae6209dd1986b761b9c861d6ccd01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b91364232e571798fe45bf8b0911bd09fca607b3e6e1ca04a384052bdedd4b206251694cac69d376c9240633b72a5af119b31271be8411f1fa35199b83cdf42
|
7
|
+
data.tar.gz: 144d396fad44caa4ddc756139861a14bda5b3ee2f336772abaf7ff55a960bea795fe06fdf00abbaf3157d744e9f3b9a94bd96f99a272ef105f4482eceeb52323
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-jacoco (0.0
|
4
|
+
danger-jacoco (0.1.0)
|
5
5
|
danger-plugin-api (~> 1.0)
|
6
6
|
nokogiri-happymapper (~> 0.6)
|
7
7
|
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
colored2 (3.1.2)
|
21
21
|
cork (0.3.0)
|
22
22
|
colored2 (~> 3.1)
|
23
|
-
danger (5.5.
|
23
|
+
danger (5.5.10)
|
24
24
|
claide (~> 1.0)
|
25
25
|
claide-plugins (>= 0.9.2)
|
26
26
|
colored2 (~> 3.1)
|
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
danger-plugin-api (1.0.0)
|
36
36
|
danger (> 2.0)
|
37
37
|
diff-lcs (1.3)
|
38
|
-
faraday (0.
|
38
|
+
faraday (0.14.0)
|
39
39
|
multipart-post (>= 1.2, < 3)
|
40
40
|
faraday-http-cache (1.3.1)
|
41
41
|
faraday (~> 0.8)
|
@@ -68,14 +68,14 @@ GEM
|
|
68
68
|
nap (1.1.0)
|
69
69
|
nenv (0.3.0)
|
70
70
|
no_proxy_fix (0.1.2)
|
71
|
-
nokogiri (1.8.
|
71
|
+
nokogiri (1.8.2)
|
72
72
|
mini_portile2 (~> 2.3.0)
|
73
73
|
nokogiri-happymapper (0.6.0)
|
74
74
|
nokogiri (~> 1.5)
|
75
75
|
notiffany (0.1.1)
|
76
76
|
nenv (~> 0.1)
|
77
77
|
shellany (~> 0.0)
|
78
|
-
octokit (4.
|
78
|
+
octokit (4.8.0)
|
79
79
|
sawyer (~> 0.8.0, >= 0.5.3)
|
80
80
|
open4 (1.3.4)
|
81
81
|
parallel (1.12.0)
|
@@ -85,7 +85,7 @@ GEM
|
|
85
85
|
pry (0.11.3)
|
86
86
|
coderay (~> 1.1.0)
|
87
87
|
method_source (~> 0.9.0)
|
88
|
-
public_suffix (3.0.
|
88
|
+
public_suffix (3.0.2)
|
89
89
|
rainbow (2.2.2)
|
90
90
|
rake
|
91
91
|
rake (12.3.0)
|
@@ -140,4 +140,4 @@ DEPENDENCIES
|
|
140
140
|
yard (~> 0.9)
|
141
141
|
|
142
142
|
BUNDLED WITH
|
143
|
-
1.16.
|
143
|
+
1.16.1
|
data/README.md
CHANGED
@@ -14,7 +14,9 @@ sudo gem install danger-jacoco
|
|
14
14
|
Add
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
jacoco.
|
17
|
+
jacoco.minimum_project_coverage_percentage = 50 # default 0
|
18
|
+
jacoco.minimum_class_coverage_percentage = 75 # default 0
|
19
|
+
jacoco.files_extension = [".java"] # default [".kt", ".java"]
|
18
20
|
jacoco.report "path/to/jacoco.xml"
|
19
21
|
```
|
20
22
|
|
data/lib/jacoco/gem_version.rb
CHANGED
data/lib/jacoco/plugin.rb
CHANGED
@@ -3,10 +3,18 @@ require 'jacoco/sax_parser'
|
|
3
3
|
module Danger
|
4
4
|
#
|
5
5
|
# @see Anton Malinskiy/danger-jacoco
|
6
|
-
# @tags jacoco, coverage, java, android
|
6
|
+
# @tags jacoco, coverage, java, android, kotlin
|
7
7
|
#
|
8
8
|
class DangerJacoco < Plugin
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :minimum_project_coverage_percentage
|
10
|
+
attr_accessor :minimum_class_coverage_percentage
|
11
|
+
attr_accessor :files_extension
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@minimum_project_coverage_percentage = 0 unless minimum_project_coverage_percentage
|
15
|
+
@minimum_class_coverage_percentage = 0 unless minimum_class_coverage_percentage
|
16
|
+
@files_extension = ['.kt', '.java'] unless files_extension
|
17
|
+
end
|
10
18
|
|
11
19
|
# Parses the xml output of jacoco to Ruby model classes
|
12
20
|
# This is slow since it's basically DOM parsing
|
@@ -21,57 +29,96 @@ module Danger
|
|
21
29
|
#
|
22
30
|
# @path path to the xml output of jacoco
|
23
31
|
# @delimiter git.modified_files returns full paths to the
|
24
|
-
# changed files. We need to get the
|
32
|
+
# changed files. We need to get the class from this path to check the
|
25
33
|
# Jacoco report,
|
26
34
|
#
|
27
|
-
# e.g. src/java/com/example/
|
35
|
+
# e.g. src/java/com/example/SomeJavaClass.java -> com/example/SomeJavaClass
|
36
|
+
# e.g. src/kotlin/com/example/SomeKotlinClass.kt -> com/example/SomeKotlinClass
|
28
37
|
#
|
29
38
|
# The default value supposes that you're using gradle structure,
|
30
|
-
# that is your path to
|
39
|
+
# that is your path to source files is something like
|
31
40
|
#
|
32
|
-
# blah/blah/java/slashed_package/Source.java
|
41
|
+
# Java => blah/blah/java/slashed_package/Source.java
|
42
|
+
# Kotlin => blah/blah/kotlin/slashed_package/Source.kt
|
33
43
|
#
|
34
|
-
def report(path, delimiter =
|
44
|
+
def report(path, delimiter = %r{\/java\/|\/kotlin\/})
|
45
|
+
setup
|
35
46
|
classes = classes(delimiter)
|
36
47
|
|
37
48
|
parser = Jacoco::SAXParser.new(classes)
|
38
49
|
Nokogiri::XML::SAX::Parser.new(parser).parse(File.open(path))
|
39
50
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
51
|
+
total_covered = total_coverage(path)
|
52
|
+
|
53
|
+
report_markdown = "### JaCoCO Code Coverage #{total_covered[:covered]}% #{total_covered[:status]}\n"
|
54
|
+
report_markdown << "| Class | Covered | Meta | Status |\n"
|
55
|
+
report_markdown << "|:---:|:---:|:---:|:---:|\n"
|
56
|
+
markdown_class(parser, report_markdown)
|
57
|
+
markdown(report_markdown)
|
58
|
+
|
59
|
+
return if total_covered[:covered] >= minimum_project_coverage_percentage
|
60
|
+
|
61
|
+
# fail danger if total coveraged is smaller than minimum_project_coverage_percentage
|
62
|
+
covered = total_covered[:covered]
|
63
|
+
raise("Total coverage of #{covered}%. Improve this to as least #{minimum_project_coverage_percentage} %")
|
44
64
|
end
|
45
65
|
|
66
|
+
# Select modified and added files in this PR
|
46
67
|
def classes(delimiter)
|
47
68
|
git = @dangerfile.git
|
48
69
|
affected_files = git.modified_files + git.added_files
|
49
|
-
affected_files.select { |file| file.end_with?
|
50
|
-
.map { |file|
|
70
|
+
affected_files.select { |file| files_extension.reduce(false) { |state, el| state || file.end_with?(el) } }
|
71
|
+
.map { |file| file.split('.').first.split(delimiter)[1] }
|
51
72
|
end
|
52
73
|
|
74
|
+
# It returns a specific class code coverage and an emoji status as well
|
53
75
|
def report_class(jacoco_class)
|
54
76
|
counters = jacoco_class.counters
|
55
77
|
branch_counter = counters.detect { |e| e.type.eql? 'BRANCH' }
|
56
78
|
line_counter = counters.detect { |e| e.type.eql? 'LINE' }
|
57
79
|
counter = branch_counter.nil? ? line_counter : branch_counter
|
80
|
+
coverage = (counter.covered.fdiv(counter.covered + counter.missed) * 100).floor
|
81
|
+
status = coverage_status(coverage, minimum_class_coverage_percentage)
|
58
82
|
|
59
|
-
|
83
|
+
{
|
84
|
+
covered: coverage,
|
85
|
+
status: status
|
86
|
+
}
|
60
87
|
end
|
61
88
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
coverage
|
89
|
+
# it returns an emoji for coverage status
|
90
|
+
def coverage_status(coverage, minimum_percentage)
|
91
|
+
if coverage < (minimum_percentage / 2) then ':skull:'
|
92
|
+
elsif coverage < minimum_percentage then ':warning:'
|
93
|
+
else ':white_check_mark:'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# It returns total of project code coverage and an emoji status as well
|
98
|
+
def total_coverage(report_path)
|
99
|
+
jacoco_report = Nokogiri::XML(File.open(report_path))
|
66
100
|
|
67
|
-
|
101
|
+
report = jacoco_report.xpath('report/counter').select { |item| item['type'] == 'INSTRUCTION' }
|
102
|
+
missed_instructions = report.first['missed'].to_f
|
103
|
+
covered_instructions = report.first['covered'].to_f
|
104
|
+
total_instructions = missed_instructions + covered_instructions
|
105
|
+
covered_percentage = (covered_instructions * 100 / total_instructions).round(2)
|
106
|
+
coverage_status = coverage_status(covered_percentage, minimum_project_coverage_percentage)
|
68
107
|
|
69
|
-
|
70
|
-
|
108
|
+
{
|
109
|
+
covered: covered_percentage,
|
110
|
+
status: coverage_status
|
111
|
+
}
|
71
112
|
end
|
72
113
|
|
73
|
-
|
74
|
-
|
114
|
+
private
|
115
|
+
|
116
|
+
def markdown_class(parser, report_markdown)
|
117
|
+
parser.classes.each do |jacoco_class| # Check metrics for each classes
|
118
|
+
rp = report_class(jacoco_class)
|
119
|
+
ln = "| `#{jacoco_class.name}` | #{rp[:covered]}% | #{minimum_class_coverage_percentage}% | #{rp[:status]} |\n"
|
120
|
+
report_markdown << ln
|
121
|
+
end
|
75
122
|
end
|
76
123
|
end
|
77
124
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-jacoco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Malinskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -172,6 +172,7 @@ extensions: []
|
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
174
|
- ".gitignore"
|
175
|
+
- ".rubocop.yml"
|
175
176
|
- ".travis.yml"
|
176
177
|
- Gemfile
|
177
178
|
- Gemfile.lock
|
@@ -218,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
219
|
version: '0'
|
219
220
|
requirements: []
|
220
221
|
rubyforge_project:
|
221
|
-
rubygems_version: 2.6.
|
222
|
+
rubygems_version: 2.6.13
|
222
223
|
signing_key:
|
223
224
|
specification_version: 4
|
224
225
|
summary: A longer description of danger-jacoco.
|