danger-shroud 2.0.0 → 2.1.0

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: c9dc7c91737f9342eb62d48933887ac740b95cdb422497c7329a5a1e51214e59
4
- data.tar.gz: e0e5805f272abc2dbc075871face1e3cb6cbf46a48a38f45f4823cc514c045d7
3
+ metadata.gz: e76505148c06d2624f1b063fe49f1ef0d93c94397d5db2b2039ef58721c80028
4
+ data.tar.gz: ca287f69c9d77b1412c6da11bb974b658b5e7e0a21aaddfc40aaad5b5f4810d6
5
5
  SHA512:
6
- metadata.gz: 2f77902e316f4d2b96a2e27254586eeebf2bef8863a2893e0faa3246a064a5ed7072b3ae10f1420d916074c422ff931d8fb6eecc917d90c73ffd88ddf13d238d
7
- data.tar.gz: 62890a17e53b620a7648e654d09b3c7a838cf6920d42ab40c61ba9d887ad2d9afc888e6a9e2d70cf3fe90c44ab28f7f4fdf307c78e66728d980ee5e9fd2fa57a
6
+ metadata.gz: c0a9e47d64b7686d1f18aec40135ace0757dd55013ac313229788cfac1de48f1c83289a438a47e6726fe61902a294f7c01ccc9258edf07992270f66c013b0db3
7
+ data.tar.gz: 0a7b43e9a7287b3a29b0a3a6bdcd0a594db1331471b0ab4b2b731e3c85efcbd92cfbbdff80414d211da3951b3d2cb5eddfc574dd45f34c33a86a2c0fb29f2f5f
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ Change Log
4
4
  Version Next
5
5
  ----------------------------
6
6
 
7
+ Version 2.1.0
8
+ ----------------------------
9
+ * Filters touched files by module
10
+ * Hides modules from report output when they have no changed files.
11
+
7
12
  Version 2.0.0
8
13
  ----------------------------
9
14
  * Upgrade to Ruby 3.1.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-shroud (2.0.0)
4
+ danger-shroud (2.1.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
  nokogiri
7
7
 
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  - [danger-shroud](#danger-shroud)
3
3
  - [Installation](#installation)
4
+ - [Configuration](#configuration)
4
5
  - [Usage Kover](#usage-kover)
5
6
  - [Parameters](#parameters)
6
7
  - [Examples](#examples)
@@ -24,6 +25,12 @@ Add this line to your application's Gemfile:
24
25
  gem 'danger-shroud'
25
26
  ```
26
27
 
28
+ ## Configuration
29
+
30
+ Shroud will default to using the filepath of your coverage report to determine which module the reported files belong to. This assumes that your Jacoco or Kover configuration will output to the default `build/reports/` directory when generating reports.
31
+
32
+ If you have a custom configuration that outputs the reports somewhere else, you can provide the module's path with the `moduleDirectory` parameter. This allows the plugin to accurately determine the module in which a file is located by matching it to the file's path prefix. A custom report location that does not have a `moduleDirectory` specified may result in files being reported in modules they do not belong to.
33
+
27
34
  ## Usage Kover
28
35
 
29
36
  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.
@@ -35,6 +42,7 @@ You can use the following parameters to control how shroud operates:
35
42
  | Param | Type | Description | Example |
36
43
  |-----------------------------|---------|---------------------------------------------------------------------------------------------|------------------------------|
37
44
  | moduleName | String | the display name of the project or module. | `'Module Name '` |
45
+ | moduleDirectory | String, nil | file path to the module to specify its location when its report `file` outputs to a custom directory. | default `nil`. |
38
46
  | file | String | file path to a Kover xml coverage report. | `'path/to/kover/report.xml'` |
39
47
  | totalProjectThreshold | Integer | defines the required percentage of total project coverage for a passing build. | default `90` |
40
48
  | modifiedFileThreshold | Integer | defines the required percentage of files modified in a PR for a passing build. | default `90` |
@@ -49,7 +57,7 @@ Running shroud with default values:
49
57
  ```ruby
50
58
  # Report coverage of modified files, fail if either total
51
59
  # project coverage or any modified file's coverage is under 90%
52
- shroud.reportKover moduleName: 'Module Name', file: 'path/to/kover/report.xml'
60
+ shroud.reportKover moduleName: 'Module Name', file: 'module/build/reports/kover/report.xml'
53
61
  ```
54
62
 
55
63
  Running shroud with custom coverage thresholds:
@@ -57,7 +65,7 @@ Running shroud with custom coverage thresholds:
57
65
  ```ruby
58
66
  # Report coverage of modified files, fail if total project coverage is under 80%,
59
67
  # or if any modified file's coverage is under 95%
60
- shroud.reportKover moduleName: 'Module Name', file: 'path/to/kover/report.xml', totalProjectThreshold: 80, modifiedFileThreshold: 95
68
+ shroud.reportKover moduleName: 'Module Name', file: 'module/build/reports/kover/report.xml', totalProjectThreshold: 80, modifiedFileThreshold: 95
61
69
  ```
62
70
 
63
71
  Warn on builds instead of fail:
@@ -65,7 +73,15 @@ Warn on builds instead of fail:
65
73
  ```ruby
66
74
  # Report coverage of modified files the same as the above example, except the
67
75
  # builds will only warn instead of fail if below project thresholds
68
- shroud.reportKover moduleName: 'Module Name', file: 'path/to/kover/report.xml', totalProjectThreshold: 80, modifiedFileThreshold: 95, failIfUnderProjectThreshold: false, failIfUnderFileThreshold: false
76
+ shroud.reportKover moduleName: 'Module Name', file: 'module/build/reports/kover/report.xml', totalProjectThreshold: 80, modifiedFileThreshold: 95, failIfUnderProjectThreshold: false, failIfUnderFileThreshold: false
77
+ ```
78
+
79
+ Running shroud with a Kover report file in a custom directory:
80
+
81
+ ```ruby
82
+ # Report coverage of modified files, specifying an explicit path to the module
83
+ # when the coverage report won't be inside of its `build/reports/` directory
84
+ shroud.reportKover moduleName: 'Module Name', moduleDirectory: 'module/', file: 'custom/path/to/kover/report.xml'
69
85
  ```
70
86
 
71
87
  ## Usage Jacoco
@@ -77,6 +93,7 @@ You can use the following parameters to control how shroud operates:
77
93
  | Param | Type | Description | Example |
78
94
  |-----------------------------|---------|---------------------------------------------------------------------------------------------|-------------------------------|
79
95
  | moduleName | String | the display name of the project or module. | `'Module Name '` |
96
+ | moduleDirectory | String, nil | file path to the module to specify its location when its report `file` outputs to a custom directory. | default `nil`. |
80
97
  | file | String | file path to a Jacoco xml coverage report. | `'path/to/jacoco/report.xml'` |
81
98
  | totalProjectThreshold | Integer | defines the required percentage of total project coverage for a passing build. | default `90` |
82
99
  | modifiedFileThreshold | Integer | defines the required percentage of files modified in a PR for a passing build. | default `90` |
@@ -93,7 +110,7 @@ Running shroud with default values:
93
110
  ```ruby
94
111
  # Report coverage of modified files, fail if either total
95
112
  # project coverage or any modified file's coverage is under 90%
96
- shroud.reportJacoco moduleName: 'Module Name', file: 'path/to/jacoco/report.xml'
113
+ shroud.reportJacoco moduleName: 'Module Name', file: 'project/module/reports/jacoco/report.xml'
97
114
  ```
98
115
 
99
116
  Running shroud with custom coverage thresholds:
@@ -101,7 +118,7 @@ Running shroud with custom coverage thresholds:
101
118
  ```ruby
102
119
  # Report coverage of modified files, fail if total project coverage is under 80%,
103
120
  # or if any modified file's coverage is under 95%
104
- shroud.reportJacoco moduleName: 'Module Name', file: 'path/to/jacoco/report.xml', totalProjectThreshold: 80, modifiedFileThreshold: 95
121
+ shroud.reportJacoco moduleName: 'Module Name', file: 'module/reports/jacoco/report.xml', totalProjectThreshold: 80, modifiedFileThreshold: 95
105
122
  ```
106
123
 
107
124
  Warn on builds instead of fail:
@@ -109,7 +126,15 @@ Warn on builds instead of fail:
109
126
  ```ruby
110
127
  # Report coverage of modified files the same as the above example, except the
111
128
  # builds will only warn instead of fail if below thresholds
112
- shroud.reportJacoco moduleName: 'Module Name', file: 'path/to/jacoco/report.xml', totalProjectThreshold: 80, modifiedFileThreshold: 95, failIfUnderProjectThreshold: false, failIfUnderFileThreshold: false
129
+ shroud.reportJacoco moduleName: 'Module Name', file: 'module/reports/jacoco/report.xml', totalProjectThreshold: 80, modifiedFileThreshold: 95, failIfUnderProjectThreshold: false, failIfUnderFileThreshold: false
130
+ ```
131
+
132
+ Running shroud with a Jacoco report file in a custom directory:
133
+
134
+ ```ruby
135
+ # Report coverage of modified files, specifying an explicit path to the module
136
+ # when the coverage report won't be inside of its `build/reports/` directory
137
+ shroud.reportKover moduleName: 'Module Name', moduleDirectory: 'module/', file: 'custom/path/to/jacoco/report.xml'
113
138
  ```
114
139
 
115
140
  ## Development
@@ -1,3 +1,3 @@
1
1
  module Shroud
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "2.1.0".freeze
3
3
  end
data/lib/shroud/plugin.rb CHANGED
@@ -68,7 +68,11 @@ module Danger
68
68
  # Report coverage on diffed files, as well as overall coverage.
69
69
  #
70
70
  # @param [String] moduleName
71
- # the display name of the project or module
71
+ # the display name of the project or module.
72
+ #
73
+ # @param [String, nil] moduleDirectory
74
+ # file path to the module to specify its location when its report `file` outputs to a custom directory.
75
+ # default nil.
72
76
  #
73
77
  # @param [String] file
74
78
  # file path to a Jacoco xml coverage report.
@@ -96,6 +100,7 @@ module Danger
96
100
  # @return [void]
97
101
  def reportJacoco(
98
102
  moduleName:,
103
+ moduleDirectory: nil,
99
104
  file:,
100
105
  totalProjectThreshold: 90,
101
106
  modifiedFileThreshold: 90,
@@ -106,6 +111,7 @@ module Danger
106
111
  internalReport(
107
112
  reportType: 'Jacoco',
108
113
  moduleName: moduleName,
114
+ moduleDirectory: moduleDirectory,
109
115
  file: file,
110
116
  totalProjectThreshold: totalProjectThreshold,
111
117
  modifiedFileThreshold: modifiedFileThreshold,
@@ -118,7 +124,11 @@ module Danger
118
124
  # Report coverage on diffed files, as well as overall coverage.
119
125
  #
120
126
  # @param [String] moduleName
121
- # the display name of the project or module
127
+ # the display name of the project or module.
128
+ #
129
+ # @param [String, nil] moduleDirectory
130
+ # file path to the module to specify its location when its report `file` outputs to a custom directory.
131
+ # default nil.
122
132
  #
123
133
  # @param [String] file
124
134
  # file path to a Kover xml coverage report.
@@ -146,6 +156,7 @@ module Danger
146
156
  # @return [void]
147
157
  def reportKover(
148
158
  moduleName:,
159
+ moduleDirectory: nil,
149
160
  file:,
150
161
  totalProjectThreshold: 90,
151
162
  modifiedFileThreshold: 90,
@@ -156,6 +167,7 @@ module Danger
156
167
  internalReport(
157
168
  reportType: 'Kover',
158
169
  moduleName: moduleName,
170
+ moduleDirectory: moduleDirectory,
159
171
  file: file,
160
172
  totalProjectThreshold: totalProjectThreshold,
161
173
  modifiedFileThreshold: modifiedFileThreshold,
@@ -168,6 +180,7 @@ module Danger
168
180
  private def internalReport(
169
181
  reportType:,
170
182
  moduleName:,
183
+ moduleDirectory:,
171
184
  file:,
172
185
  totalProjectThreshold:,
173
186
  modifiedFileThreshold:,
@@ -187,9 +200,17 @@ module Danger
187
200
  total = missed + covered
188
201
  coveragePercent = (covered / total.to_f) * 100
189
202
 
190
- # get array of files names touched by this PR (modified + added)
191
- touchedFileNames = @dangerfile.git.modified_files.map { |file| File.basename(file) }
192
- touchedFileNames += @dangerfile.git.added_files.map { |file| File.basename(file) }
203
+ # if we are provided an explicit path to the module directory, use that.
204
+ # the default location for a Kover or Jacoco report is in the build directory of the module.
205
+ # if we're in the build directory then we can determine the module's file path for sorting.
206
+ modulePath = moduleDirectory || (file.include?('/build/') ? file.split('/build/').first + '/' : nil)
207
+
208
+ # get array of files names within the specified module touched by this PR (modified + added).
209
+ # if we have the path of the module, use that to filter the files, otherwise fallback to
210
+ # the previous behavior when it can't be determined.
211
+ touchedFileNames = (@dangerfile.git.modified_files + @dangerfile.git.added_files)
212
+ .select { |path| modulePath.nil? || path.start_with?(modulePath) }
213
+ .map { |path| File.basename(path) }
193
214
 
194
215
  # used to later report files that were modified but not included in the report
195
216
  fileNamesNotInReport = []
@@ -213,6 +234,11 @@ module Danger
213
234
  end
214
235
  end
215
236
 
237
+ # don't output anything when the module has no touched files
238
+ if (touchedFilesHash.empty?)
239
+ return
240
+ end
241
+
216
242
  puts "Here are unreported files"
217
243
  puts fileNamesNotInReport.to_s
218
244
  puts "Here is the touched files coverage hash"
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: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - andrewhaisting
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-26 00:00:00.000000000 Z
11
+ date: 2026-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api