danger-shroud 0.0.4 → 0.0.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
2
  SHA256:
3
- metadata.gz: 00edfafb1266b9496abe1346a20decc2625762cdbb14ce3ee11feb474dbf9773
4
- data.tar.gz: 766eae63a08b0dd893b1dc00bcb07afb24a55b460f599fbb1aed2360d0f28f1e
3
+ metadata.gz: ef8bbfd7e32b3948a01570f48a893401eda640342e58fb4721c6da5dc66ea94e
4
+ data.tar.gz: 8b4d3599b8eb136074632beba3c18c900ffea7b9ebc0d75abcaf9b986724e0d9
5
5
  SHA512:
6
- metadata.gz: 7805de3876afc42b9d3961a005038de0e27dc2bff08efddc701a4644c8c51d3e082574f93513923d15b4197b0cc7165ecfc50a36d767d9fb3980c45bb71591ec
7
- data.tar.gz: 6e75b7bb5a229690307ecb4e0df6603b9f6a15e3319c243c0dcb8618f66d6f05b12c073972e66ec41d0f30552affb938ff23bf7739b5d09e29fbb3ffa1cff327
6
+ metadata.gz: af7c215e0fbaf9a39a6d7af965e3f322bb0a49fe9703782df35f74b016b4c7d5e081f14a769c9c4a0c70d6c9c48036124982b93ef59f5556dff43dbfa219a548
7
+ data.tar.gz: 31bc8ee27909c4164b77b276d69f9c8d30d49fb3e0ee32a4d60c64774e588a6a2d5c1fb0e17d145bd7dbc8867213de7f753dc92d1fccdec4ebcb8f7c5e8094d6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-shroud (0.0.4)
4
+ danger-shroud (0.0.5)
5
5
  danger-plugin-api (~> 1.0)
6
6
  nokogiri
7
7
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # danger-shroud
2
2
 
3
- A danger plugin for enforcing code coverage coverage via a Jacoco coverage reports.
3
+ A danger plugin for enforcing code coverage coverage via a Kover or Jacoco coverage report.
4
4
 
5
5
  ![Shroud Banner Image](images/bannerImage.png)
6
6
 
@@ -12,7 +12,36 @@ Add this line to your application's Gemfile:
12
12
  gem 'danger-shroud'
13
13
  ```
14
14
 
15
- ## Usage
15
+ ## Usage Kover
16
+
17
+ Shroud depends on having a Kover coverage report generated for your project. For Android projects, [kotlinx-kover](https://github.com/Kotlin/kotlinx-kover) works well.
18
+
19
+ Running shroud with default values:
20
+
21
+ ```ruby
22
+ # Report coverage of modified files, fail if either total
23
+ # project coverage or any modified file's coverage is under 90%
24
+ shroud.reportKover 'Module Name', 'path/to/kover/report.xml'
25
+ ```
26
+
27
+ Running shroud with custom coverage thresholds:
28
+
29
+ ```ruby
30
+ # Report coverage of modified files, fail if total project coverage is under 80%,
31
+ # or if any modified file's coverage is under 95%
32
+ shroud.reportKover 'Module Name', 'path/to/kover/report.xml', 80, 95
33
+ ```
34
+
35
+ Warn on builds instead of fail:
36
+
37
+ ```ruby
38
+ # Report coverage of modified files the same as the above example, except the
39
+ # builds will only warn instead of fail if below thresholds
40
+ shroud.reportKover 'Module Name', 'path/to/kover/report.xml', 80, 95, false
41
+ ```
42
+
43
+
44
+ ## Usage Jacoco
16
45
 
17
46
  Shroud depends on having a Jacoco coverage report generated for your project. For Android projects, [jacoco-android-gradle-plugin](https://github.com/arturdm/jacoco-android-gradle-plugin) works well.
18
47
 
@@ -21,7 +50,7 @@ Running shroud with default values:
21
50
  ```ruby
22
51
  # Report coverage of modified files, fail if either total
23
52
  # project coverage or any modified file's coverage is under 90%
24
- shroud.report 'path/to/jacoco/report.xml'
53
+ shroud.reportJacoco 'Module Name', 'path/to/jacoco/report.xml'
25
54
  ```
26
55
 
27
56
  Running shroud with custom coverage thresholds:
@@ -29,7 +58,7 @@ Running shroud with custom coverage thresholds:
29
58
  ```ruby
30
59
  # Report coverage of modified files, fail if total project coverage is under 80%,
31
60
  # or if any modified file's coverage is under 95%
32
- shroud.report 'path/to/jacoco/report.xml', 80, 95
61
+ shroud.reportJacoco 'Module Name', 'path/to/jacoco/report.xml', 80, 95
33
62
  ```
34
63
 
35
64
  Warn on builds instead of fail:
@@ -37,7 +66,7 @@ Warn on builds instead of fail:
37
66
  ```ruby
38
67
  # Report coverage of modified files the same as the above example, except the
39
68
  # builds will only warn instead of fail if below thresholds
40
- shroud.report 'path/to/jacoco/report.xml', 80, 95, false
69
+ shroud.reportJacoco 'Module Name', 'path/to/jacoco/report.xml', 80, 95, false
41
70
  ```
42
71
 
43
72
 
@@ -1,3 +1,3 @@
1
1
  module Shroud
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.0.5".freeze
3
3
  end
data/lib/shroud/plugin.rb CHANGED
@@ -2,33 +2,53 @@ require 'nokogiri'
2
2
 
3
3
  module Danger
4
4
 
5
- # Parse a Jacoco report to enforce code coverage on CI. Results are passed out as a table in markdown.
5
+ # Parse a Kover or Jacoco report to enforce code coverage on CI. Results are passed out as a table in markdown.
6
6
  #
7
- # Shroud depends on having a Jacoco coverage report generated for your project. For Android projects,
8
- # [jacoco-android-gradle-plugin](https://github.com/arturdm/jacoco-android-gradle-plugin) works well.
7
+ # Shroud depends on having a Kover or Jacoco coverage report generated for your project.
9
8
  #
10
- # @example Running shroud with default values
9
+ #
10
+ # @example Running Shroud with default values for Kover
11
11
  #
12
12
  # # Report coverage of modified files, fail if either total project coverage
13
13
  # # or any modified file's coverage is under 90%
14
- # shroud.report 'path/to/jacoco/report.xml'
14
+ # shroud.reportKover 'Project Name', 'path/to/kover/report.xml'
15
15
  #
16
- # @example Running shroud with custom coverage thresholds
16
+ # @example Running Shroud with custom coverage thresholds for Kover
17
17
  #
18
18
  # # Report coverage of modified files, fail if total project coverage is under 80%,
19
19
  # # or if any modified file's coverage is under 95%
20
- # shroud.report 'path/to/jacoco/report.xml', 80, 95
20
+ # shroud.reportKover 'Project Name', 'path/to/kover/report.xml', 80, 95
21
21
  #
22
- # @example Warn on builds instead of fail
22
+ # @example Warn on builds instead of fail for Kover
23
23
  #
24
24
  # # Report coverage of modified files the same as the above example, except the
25
25
  # # builds will only warn instead of fail if below thresholds
26
- # shroud.report 'path/to/jacoco/report.xml', 80, 95, false
26
+ # shroud.reportKover 'Project Name', 'path/to/kover/report.xml', 80, 95, false
27
+ #
28
+ # @example Running Shroud with default values for Jacoco
29
+ #
30
+ # # Report coverage of modified files, fail if either total project coverage
31
+ # # or any modified file's coverage is under 90%
32
+ # shroud.reportJacoco 'Project Name', 'path/to/jacoco/report.xml'
33
+ #
34
+ # @example Running Shroud with custom coverage thresholds for Jacoco
35
+ #
36
+ # # Report coverage of modified files, fail if total project coverage is under 80%,
37
+ # # or if any modified file's coverage is under 95%
38
+ # shroud.reportJacoco 'Project Name', 'path/to/jacoco/report.xml', 80, 95
39
+ #
40
+ # @example Warn on builds instead of fail for Jacoco
41
+ #
42
+ # # Report coverage of modified files the same as the above example, except the
43
+ # # builds will only warn instead of fail if below thresholds
44
+ # shroud.reportJacoco 'Project Name', 'path/to/jacoco/report.xml', 80, 95, false
27
45
  #
28
- # @tags android, jacoco, coverage
46
+ # @tags android, kover, jacoco, coverage
29
47
  #
30
48
  class DangerShroud < Plugin
31
49
 
50
+ # <b>DEPRECATED:</b> Please use <tt>reportJacoco</tt> or <tt>reportKover</tt> instead.
51
+ #
32
52
  # Report coverage on diffed files, as well as overall coverage.
33
53
  #
34
54
  # @param [String] file
@@ -48,8 +68,63 @@ module Danger
48
68
  #
49
69
  # @return [void]
50
70
  def report(file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderThreshold = true)
71
+ warn "[DEPRECATION] `report` is deprecated. Please use `reportJacoco` or `reportKover` instead."
72
+ reportJacoco('Project', file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderThreshold = true)
73
+ end
74
+
75
+ # Report coverage on diffed files, as well as overall coverage.
76
+ #
77
+ # @param [String] moduleName
78
+ # the display name of the project or module
79
+ #
80
+ # @param [String] file
81
+ # file path to a Jacoco xml coverage report.
82
+ #
83
+ # @param [Integer] totalProjectThreshold
84
+ # defines the required percentage of total project coverage for a passing build.
85
+ # default 90.
86
+ #
87
+ # @param [Integer] modifiedFileThreshold
88
+ # defines the required percentage of files modified in a PR for a passing build.
89
+ # default 90.
90
+ #
91
+ # @param [Boolean] failIfUnderThreshold
92
+ # if true, will fail builds that are under the provided thresholds. if false, will only warn.
93
+ # default true.
94
+ #
95
+ # @return [void]
96
+ def reportJacoco(moduleName, file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderThreshold = true)
97
+ internalReport('Jacoco', moduleName, file, totalProjectThreshold, modifiedFileThreshold, failIfUnderThreshold)
98
+ end
99
+
100
+ # Report coverage on diffed files, as well as overall coverage.
101
+ #
102
+ # @param [String] moduleName
103
+ # the display name of the project or module
104
+ #
105
+ # @param [String] file
106
+ # file path to a Kover xml coverage report.
107
+ #
108
+ # @param [Integer] totalProjectThreshold
109
+ # defines the required percentage of total project coverage for a passing build.
110
+ # default 90.
111
+ #
112
+ # @param [Integer] modifiedFileThreshold
113
+ # defines the required percentage of files modified in a PR for a passing build.
114
+ # default 90.
115
+ #
116
+ # @param [Boolean] failIfUnderThreshold
117
+ # if true, will fail builds that are under the provided thresholds. if false, will only warn.
118
+ # default true.
119
+ #
120
+ # @return [void]
121
+ def reportKover(moduleName, file, totalProjectThreshold = 90, modifiedFileThreshold = 90, failIfUnderThreshold = true)
122
+ internalReport('Kover', moduleName, file, totalProjectThreshold, modifiedFileThreshold, failIfUnderThreshold)
123
+ end
124
+
125
+ private def internalReport(reportType, moduleName, file, totalProjectThreshold, modifiedFileThreshold, failIfUnderThreshold)
51
126
  raise "Please specify file name." if file.empty?
52
- raise "No jacoco xml report found at #{file}" unless File.exist? file
127
+ raise "No #{reportType} xml report found at #{file}" unless File.exist? file
53
128
  rawXml = File.read(file)
54
129
  parsedXml = Nokogiri::XML.parse(rawXml)
55
130
  totalInstructionCoverage = parsedXml.xpath("/report/counter[@type='INSTRUCTION']")
@@ -62,8 +137,8 @@ module Danger
62
137
  touchedFileNames = @dangerfile.git.modified_files.map { |file| File.basename(file) }
63
138
  touchedFileNames += @dangerfile.git.added_files.map { |file| File.basename(file) }
64
139
 
65
- # used to later report files that were modified but not included in the jacoco report
66
- fileNamesNotInJacocoReport = []
140
+ # used to later report files that were modified but not included in the report
141
+ fileNamesNotInReport = []
67
142
 
68
143
  # hash for keeping track of coverage per filename: {filename => coverage percent}
69
144
  touchedFilesHash = {}
@@ -80,16 +155,16 @@ module Danger
80
155
  end
81
156
  touchedFilesHash[touchedFileName] = (covered.to_f / (missed + covered)) * 100
82
157
  else
83
- fileNamesNotInJacocoReport << touchedFileName
158
+ fileNamesNotInReport << touchedFileName
84
159
  end
85
160
  end
86
161
 
87
162
  puts "Here are unreported files"
88
- puts fileNamesNotInJacocoReport.to_s
163
+ puts fileNamesNotInReport.to_s
89
164
  puts "Here is the touched files coverage hash"
90
165
  puts touchedFilesHash
91
166
 
92
- output = "## 🧛 Project Code Coverage: **`#{'%.2f' % coveragePercent}%`**\n"
167
+ output = "## 🧛 #{moduleName} Code Coverage: **`#{'%.2f' % coveragePercent}%`**\n"
93
168
 
94
169
  output << "### Coverage of Modified Files:\n"
95
170
  output << "File | Coverage\n"
@@ -111,7 +186,7 @@ module Danger
111
186
  end
112
187
 
113
188
  output << "### Modified Files Not Found In Coverage Report:\n"
114
- fileNamesNotInJacocoReport.sort.each do |unreportedFileName|
189
+ fileNamesNotInReport.sort.each do |unreportedFileName|
115
190
  output << "#{unreportedFileName}\n"
116
191
  end
117
192
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-shroud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - andrewhaisting
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-13 00:00:00.000000000 Z
11
+ date: 2022-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api