danger-jacoco 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 41f06316cc4d1805a8a86dbd4957500b059b1a96
4
- data.tar.gz: f03bd63af127ad7b93e4e284602451e6307e6f34
2
+ SHA256:
3
+ metadata.gz: be717547463cb80933a9d0a26dc3c8d54e28ab790ee586f3c85ba008a05a32ac
4
+ data.tar.gz: 5d4c4871ab84ca86896e9c0bc87d65deb833222772bca6b94e189382402f6309
5
5
  SHA512:
6
- metadata.gz: 472aaa07a8b9592fd940054882f52d03207cdc45a9d4703bda6fe087fd03f0da54a5409f0a2f8f1437cdb9b58b675a06ffbc97c8cb325a69c47275c51e7644e4
7
- data.tar.gz: da9c29738c04da81dde72eda8320209339dbbb4b2f9a6f91cf4a61ae9f283439182fd64c8b2aa4a5e7a05716300d523c5e619815bcc7b7a10ba2d1d47ebaf8d6
6
+ metadata.gz: 28114a17c2544c7780a282edc04660756b0b4b3da8a49c87da7ddae43c71fadbf57f1cc7c887430a6bc3b77115be214e46f6116232ddcbe75b47ed9f4701a969
7
+ data.tar.gz: 4958daa6252fdccaf330c6b752cc1bc51a57cfa4988c72fbf6ef8815472ff11df11e212535a43c2f4a2bf367c7de541647b45f2093c89ad5bb4b1b1fa1204e74
@@ -0,0 +1,12 @@
1
+ name: ci
2
+ on: [push]
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-18.04
6
+ steps:
7
+ - uses: actions/checkout@v1
8
+ - uses: actions/setup-ruby@v1
9
+ with:
10
+ ruby-version: '2.6.x'
11
+ - run: bundle install
12
+ - run: bundle exec rake spec
@@ -0,0 +1,22 @@
1
+ name: deploy-release
2
+ on:
3
+ push:
4
+ tags: '*'
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v1
10
+ - uses: actions/setup-ruby@v1
11
+ with:
12
+ ruby-version: '2.6.x'
13
+ - run: bundle install
14
+ - run: bundle exec rake spec
15
+ - name: setup credentials
16
+ env:
17
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
18
+ run: |
19
+ mkdir ~/.gem
20
+ echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
21
+ chmod 0600 ~/.gem/credentials
22
+ - run: bundle exec rake release
data/README.md CHANGED
@@ -15,6 +15,13 @@ Add
15
15
 
16
16
  ```ruby
17
17
  jacoco.minimum_project_coverage_percentage = 50 # default 0
18
+ jacoco.minimum_package_coverage_map = { # optional (default is empty)
19
+ 'com/package/' => 55,
20
+ 'com/package/more/specific/' => 15
21
+ }
22
+ jacoco.minimum_class_coverage_map = { # optional (default is empty)
23
+ 'com/package/more/specific/ClassName' => 15
24
+ }
18
25
  jacoco.minimum_class_coverage_percentage = 75 # default 0
19
26
  jacoco.files_extension = [".java"] # default [".kt", ".java"]
20
27
  jacoco.report("path/to/jacoco.xml", "http://jacoco-html-reports/")
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jacoco/gem_version'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jacoco/plugin'
2
4
 
3
5
  require 'jacoco/dom_parser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jacoco
2
4
  # DOM parser for Jacoco report
3
5
  class DOMParser
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jacoco
2
- VERSION = '0.1.4'.freeze
4
+ VERSION = '0.1.5'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/counter'
3
5
  require 'jacoco/model/method'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
 
3
5
  module Jacoco
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/group'
3
5
  require 'jacoco/model/package'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/counter'
3
5
  require 'jacoco/model/method'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/counter'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/class'
3
5
  require 'jacoco/model/sourcefile'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
  require 'jacoco/model/session_info'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
 
3
5
  module Jacoco
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'happymapper'
2
4
 
3
5
  module Jacoco
@@ -1,19 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jacoco/sax_parser'
2
4
 
3
5
  module Danger
6
+ # Verify code coverage inside your projects
7
+ # This is done using the jacoco output
8
+ # Results are passed out as a table in markdown
9
+ #
10
+ # @example Verify coverage
11
+ # jacoco.minimum_project_coverage_percentage = 50
12
+ #
13
+ # @example Verify coverage per package
14
+ # jacoco.minimum_package_coverage_map = { # optional (default is empty)
15
+ # 'com/package/' => 55,
16
+ # 'com/package/more/specific/' => 15
17
+ # }
4
18
  #
5
19
  # @see Anton Malinskiy/danger-jacoco
6
20
  # @tags jacoco, coverage, java, android, kotlin
7
21
  #
8
- class DangerJacoco < Plugin
22
+ class DangerJacoco < Plugin # rubocop:disable Metrics/ClassLength
9
23
  attr_accessor :minimum_project_coverage_percentage
10
24
  attr_accessor :minimum_class_coverage_percentage
11
25
  attr_accessor :files_extension
26
+ attr_accessor :minimum_package_coverage_map
12
27
  attr_accessor :minimum_class_coverage_map
13
28
 
29
+ # Initialize the plugin with configured parameters or defaults
14
30
  def setup
15
31
  @minimum_project_coverage_percentage = 0 unless minimum_project_coverage_percentage
16
32
  @minimum_class_coverage_percentage = 0 unless minimum_class_coverage_percentage
33
+ @minimum_package_coverage_map = {} unless minimum_package_coverage_map
17
34
  @minimum_class_coverage_map = {} unless minimum_class_coverage_map
18
35
  @files_extension = ['.kt', '.java'] unless files_extension
19
36
  end
@@ -54,8 +71,8 @@ module Danger
54
71
  total_covered = total_coverage(path)
55
72
 
56
73
  report_markdown = "### JaCoCO Code Coverage #{total_covered[:covered]}% #{total_covered[:status]}\n"
57
- report_markdown << "| Class | Covered | Meta | Status |\n"
58
- report_markdown << "|:---|:---:|:---:|:---:|\n"
74
+ report_markdown += "| Class | Covered | Meta | Status |\n"
75
+ report_markdown += "|:---|:---:|:---:|:---:|\n"
59
76
  class_coverage_above_minimum = markdown_class(parser, report_markdown, report_url)
60
77
  markdown(report_markdown)
61
78
 
@@ -75,6 +92,7 @@ module Danger
75
92
  counter = coverage_counter(jacoco_class)
76
93
  coverage = (counter.covered.fdiv(counter.covered + counter.missed) * 100).floor
77
94
  required_coverage = minimum_class_coverage_map[jacoco_class.name]
95
+ required_coverage = package_coverage(jacoco_class.name) if required_coverage.nil?
78
96
  required_coverage = minimum_class_coverage_percentage if required_coverage.nil?
79
97
  status = coverage_status(coverage, required_coverage)
80
98
 
@@ -85,6 +103,20 @@ module Danger
85
103
  }
86
104
  end
87
105
 
106
+ # it returns the most suitable coverage by package name to class or nil
107
+ def package_coverage(class_name)
108
+ path = class_name
109
+ package_parts = class_name.split('/')
110
+ package_parts.reverse_each do |item|
111
+ size = item.size
112
+ path = path[0...-size]
113
+ coverage = minimum_package_coverage_map[path]
114
+ path = path[0...-1] unless path.empty?
115
+ return coverage unless coverage.nil?
116
+ end
117
+ nil
118
+ end
119
+
88
120
  # it returns an emoji for coverage status
89
121
  def coverage_status(coverage, minimum_percentage)
90
122
  if coverage < (minimum_percentage / 2) then ':skull:'
@@ -152,12 +184,11 @@ module Danger
152
184
 
153
185
  def report_link(class_name, report_url)
154
186
  if report_url.empty?
155
- "`#{class_name}`"
156
- else
157
- report_filepath = class_name.gsub(/\/(?=[^\/]*\/.)/, '.') + ".html"
158
- "[`#{class_name}`](#{report_url + report_filepath})"
187
+ "`#{class_name}`"
188
+ else
189
+ report_filepath = class_name.gsub(%r{/(?=[^/]*/.)}, '.') + '.html'
190
+ "[`#{class_name}`](#{report_url + report_filepath})"
159
191
  end
160
192
  end
161
-
162
193
  end
163
194
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'nokogiri'
2
4
 
3
5
  module Jacoco
@@ -1,16 +1,21 @@
1
- require File.expand_path("../spec_helper", __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
- module Danger
3
+ # rubocop:disable LineLength
4
+
5
+ # rubocop:disable BlockLength
6
+
7
+ require File.expand_path('spec_helper', __dir__)
4
8
 
9
+ module Danger
5
10
  describe Danger::DangerJacoco do
6
- it "should be a plugin" do
11
+ it 'should be a plugin' do
7
12
  expect(Danger::DangerJacoco.new(nil)).to be_a Danger::Plugin
8
13
  end
9
14
 
10
15
  #
11
16
  # You should test your custom attributes and methods here
12
17
  #
13
- describe "with Dangerfile" do
18
+ describe 'with Dangerfile' do
14
19
  before do
15
20
  @dangerfile = testing_dangerfile
16
21
  @my_plugin = @dangerfile.jacoco
@@ -20,25 +25,91 @@ module Danger
20
25
 
21
26
  allow(@dangerfile.git).to receive(:modified_files).and_return(modified_files)
22
27
  allow(@dangerfile.git).to receive(:added_files).and_return(added_files)
28
+ end
29
+
30
+ it :report do
31
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
32
+
33
+ @my_plugin.minimum_project_coverage_percentage = 50
34
+ @my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 100 }
35
+
36
+ @my_plugin.report path_a
23
37
 
38
+ expect(@dangerfile.status_report[:errors]).to eq(['Total coverage of 32.9%. Improve this to at least 50%',
39
+ 'Class coverage is below minimum. Improve to at least 0%'])
40
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('### JaCoCO Code Coverage 32.9% :warning:')
41
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| Class | Covered | Meta | Status |')
42
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('|:---|:---:|:---:|:---:|')
43
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 100% | :warning: |')
24
44
  end
25
45
 
46
+ it 'test with package coverage' do
47
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
26
48
 
27
- it :report do
49
+ @my_plugin.minimum_project_coverage_percentage = 50
50
+ @my_plugin.minimum_package_coverage_map = { 'com/example/' => 70 }
51
+
52
+ @my_plugin.report path_a
53
+
54
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
55
+ end
56
+
57
+ it 'test with bigger overlapped package coverage' do
28
58
  path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
29
59
 
30
60
  @my_plugin.minimum_project_coverage_percentage = 50
31
- @my_plugin.minimum_class_coverage_map = { "com/example/CachedRepository" => 100}
61
+ @my_plugin.minimum_package_coverage_map = {
62
+ 'com/example/' => 70,
63
+ 'com/' => 90
64
+ }
32
65
 
33
66
  @my_plugin.report path_a
34
67
 
35
- expect(@dangerfile.status_report[:errors]).to eq(["Total coverage of 32.9%. Improve this to at least 50%",
36
- "Class coverage is below minimum. Improve to at least 0%"])
37
- expect(@dangerfile.status_report[:markdowns][0].message).to include("### JaCoCO Code Coverage 32.9% :warning:")
38
- expect(@dangerfile.status_report[:markdowns][0].message).to include("| Class | Covered | Meta | Status |")
39
- expect(@dangerfile.status_report[:markdowns][0].message).to include("|:---|:---:|:---:|:---:|")
40
- expect(@dangerfile.status_report[:markdowns][0].message).to include("| `com/example/CachedRepository` | 50% | 100% | :warning: |")
68
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 70% | :warning: |')
69
+ end
70
+
71
+ it 'test with lower overlapped package coverage' do
72
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
41
73
 
74
+ @my_plugin.minimum_project_coverage_percentage = 50
75
+ @my_plugin.minimum_package_coverage_map = {
76
+ 'com/example/' => 77,
77
+ 'com/' => 30
78
+ }
79
+
80
+ @my_plugin.report path_a
81
+
82
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 77% | :warning: |')
83
+ end
84
+
85
+ it 'test with overlapped package coverage and bigger class coverage' do
86
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
87
+
88
+ @my_plugin.minimum_project_coverage_percentage = 50
89
+ @my_plugin.minimum_package_coverage_map = {
90
+ 'com/example/' => 77,
91
+ 'com/' => 30
92
+ }
93
+ @my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 100 }
94
+
95
+ @my_plugin.report path_a
96
+
97
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 100% | :warning: |')
98
+ end
99
+
100
+ it 'test with overlapped package coverage and lowwer class coverage' do
101
+ path_a = "#{File.dirname(__FILE__)}/fixtures/output_a.xml"
102
+
103
+ @my_plugin.minimum_project_coverage_percentage = 50
104
+ @my_plugin.minimum_package_coverage_map = {
105
+ 'com/example/' => 90,
106
+ 'com/' => 85
107
+ }
108
+ @my_plugin.minimum_class_coverage_map = { 'com/example/CachedRepository' => 80 }
109
+
110
+ @my_plugin.report path_a
111
+
112
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| `com/example/CachedRepository` | 50% | 80% | :warning: |')
42
113
  end
43
114
 
44
115
  it 'adds a link to report' do
@@ -49,10 +120,11 @@ module Danger
49
120
 
50
121
  @my_plugin.report(path_a, 'http://test.com/')
51
122
 
52
- expect(@dangerfile.status_report[:markdowns][0].message).to include("| [`com/example/CachedRepository`](http://test.com/com.example/CachedRepository.html) | 50% | 80% | :warning: |")
53
-
123
+ expect(@dangerfile.status_report[:markdowns][0].message).to include('| [`com/example/CachedRepository`](http://test.com/com.example/CachedRepository.html) | 50% | 80% | :warning: |')
54
124
  end
55
-
56
125
  end
57
126
  end
58
127
  end
128
+
129
+ # rubocop:enable LineLength
130
+ # rubocop:enable BlockLength
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
- ROOT = Pathname.new(File.expand_path('../../', __FILE__))
4
+ ROOT = Pathname.new(File.expand_path('..', __dir__))
3
5
  $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
6
  $LOAD_PATH.unshift((ROOT + 'spec').to_s)
5
7
 
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Malinskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -171,6 +171,8 @@ executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
+ - ".github/workflows/ci.yaml"
175
+ - ".github/workflows/release.yaml"
174
176
  - ".gitignore"
175
177
  - ".rubocop.yml"
176
178
  - ".travis.yml"
@@ -217,8 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
219
  - !ruby/object:Gem::Version
218
220
  version: '0'
219
221
  requirements: []
220
- rubyforge_project:
221
- rubygems_version: 2.6.13
222
+ rubygems_version: 3.0.3
222
223
  signing_key:
223
224
  specification_version: 4
224
225
  summary: A longer description of danger-jacoco.