danger-undercover 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb04717e10cd473267cb307eb0d4b4d0fcd4301fc9e5aa49addf8167cc7b8dbe
4
- data.tar.gz: be57b82ff15f6808c4cb4c7ec835c347e1907d4f152a0e2ba8ffc56a83f71cbb
3
+ metadata.gz: b5ba1eda2ac42f3e902619f81a4c6eda0371c5add9c8f6e4a63dbe69e54ec3d6
4
+ data.tar.gz: 3336e15c47eb09127809cabc2ea4b6ee7a0e646bf1f2be7ad7f631a4052cdecb
5
5
  SHA512:
6
- metadata.gz: 826db9606d9cdb7bd8baf9b2090654b03412a00bdae6921bb662aee6267730c4c6c5fabc85b04f3380e9ce6b38d5487c1b81e74d4eefbeaeab93740d9d6bdfdf
7
- data.tar.gz: bbed20bc346d9118d268d042c18427c1e856f973f9afbabb58dcbccb8ebe66a08fe8d66152fc479e4e602ead77647465db25c685dcfe56f84a16f39d4bfbcb16
6
+ metadata.gz: cf71b015300f51aa2d57172a03032a4534ce9fad0e83f97e840e4c951c2d4e042253fcc4581fcc725e4fc2343eb3d357aef557904d8235204e232a1dfda77fed
7
+ data.tar.gz: a4323eb9d539a83fe0041ad528023d7f175d075f4f4091126fb5676c466096dacb614f43302d6c122b99a56cb919fc834a98d6c845788b08a9caf0c63ac4741b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-undercover (1.0.0)
4
+ danger-undercover (1.1.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
@@ -19,7 +19,7 @@ GEM
19
19
  colored2 (3.1.2)
20
20
  cork (0.3.0)
21
21
  colored2 (~> 3.1)
22
- danger (8.0.6)
22
+ danger (8.1.0)
23
23
  claide (~> 1.0)
24
24
  claide-plugins (>= 0.9.2)
25
25
  colored2 (~> 3.1)
@@ -35,8 +35,9 @@ GEM
35
35
  danger-plugin-api (1.0.0)
36
36
  danger (> 2.0)
37
37
  diff-lcs (1.4.4)
38
- faraday (1.0.1)
38
+ faraday (1.1.0)
39
39
  multipart-post (>= 1.2, < 3)
40
+ ruby2_keywords
40
41
  faraday-http-cache (2.2.0)
41
42
  faraday (>= 0.8)
42
43
  ffi (1.13.1)
@@ -117,6 +118,7 @@ GEM
117
118
  rubocop-ast (0.7.1)
118
119
  parser (>= 2.7.1.5)
119
120
  ruby-progressbar (1.10.1)
121
+ ruby2_keywords (0.0.2)
120
122
  sawyer (0.8.2)
121
123
  addressable (>= 2.3.5)
122
124
  faraday (> 0.8, < 2.0)
data/README.md CHANGED
@@ -15,10 +15,16 @@ To know more about running undercover [visit here](https://github.com/grodowski/
15
15
  > Use the `-c --compare ref` flag to specify a git ref (commit hash, branch name, tag) to compare against.
16
16
  **This is a recommended usage for CI/CD build environments**, as `undercover` will `exit 1` if there are any warnings.
17
17
 
18
- Run the below command to output undercover report to a `txt` file which this plugin will use to geneate PR comments.
19
- To use it on a CI server, run this command before running `Danger` so that the file is created beforehand.
18
+ This plugin provides a command `undercover-report` that uses `undercover` command from
19
+ [Undercover](https://github.com/grodowski/undercover) gem. It takes all the options that `undercover` command takes.
20
20
 
21
- $ undercover -c $compare_git_ref > coverage/undercover.txt
21
+ They both works in the same way but what `undercover-report` extra does is it prints `undercover` report to a default
22
+ file in `coverage/undercover.txt`. This makes using `undercover` in CI server much easier.
23
+
24
+ To use it on a CI server, run the below command before running `Danger` so that the report file is created beforehand
25
+ which `Danger` will use..
26
+
27
+ $ undercover-report -c $compare_git_ref
22
28
 
23
29
  >Here $compare_git_ref as per undercover documentation, can be a commit hash, branch name, or tag. i.e. origin/master
24
30
  , origin/development
@@ -27,7 +33,7 @@ To use it on a CI server, run this command before running `Danger` so that the f
27
33
  Then in your `Dangerfile` add the following line with the output file
28
34
 
29
35
  ```ruby
30
- undercover.report 'coverage/undercover.txt'
36
+ undercover.report
31
37
  ```
32
38
 
33
39
  ## Development
@@ -0,0 +1,10 @@
1
+ # bin/undercover_report
2
+
3
+ #!/usr/bin/env ruby
4
+ # frozen_string_literal: true
5
+
6
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
7
+
8
+ require 'undercover/cli'
9
+
10
+ puts DangerUndercover::CLI.run(ARGV)
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ module DangerUndercover
6
+ # module for undercover-report
7
+ module CLI
8
+ class << self
9
+ # Runs the undercover command with provided arguments
10
+ # and writes the output to a file
11
+ # @return [String]
12
+ #
13
+ def run(args = nil)
14
+ undercover_output = `undercover #{args&.join(' ')}`
15
+
16
+ File.open(output_file, 'w') do |f|
17
+ f.write(undercover_output)
18
+ end
19
+
20
+ undercover_output
21
+ end
22
+
23
+ private
24
+
25
+ # Returns the file to write report to
26
+ # @return [String]
27
+ #
28
+ def output_file
29
+ create_directory!
30
+
31
+ File.join(output_directory, 'undercover.txt')
32
+ end
33
+
34
+ # Creates directory if doesn't exists
35
+ # @return [String]
36
+ #
37
+ def create_directory!
38
+ return if Dir.exist?(output_directory)
39
+
40
+ FileUtils.mkdir_p(output_directory)
41
+ end
42
+
43
+ # Output directory
44
+ # @return [String]
45
+ #
46
+ def output_directory
47
+ File.join(Dir.getwd, 'coverage')
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Undercover
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -16,6 +16,7 @@ module Danger
16
16
  #
17
17
  class DangerUndercover < Plugin
18
18
  VALID_FILE_FORMAT = '.txt'
19
+ DEFAULT_PATH = 'coverage/undercover.txt'
19
20
 
20
21
  # Checks the file validity and warns if no file is found
21
22
  # if a valid file is found then if there are no changes,
@@ -23,15 +24,15 @@ module Danger
23
24
  # If there are reports then it shows the report as a warning in danger.
24
25
  # @return [void]
25
26
  #
26
- def report(undercover_path, sticky: true)
27
+ def report(undercover_path = DEFAULT_PATH, sticky: true)
27
28
  return fail('Undercover: coverage report cannot be found.') unless valid_file? undercover_path
28
29
 
29
- report = File.open(undercover_path).read
30
+ report = File.open(undercover_path).read.force_encoding('UTF-8')
30
31
 
31
- if report.match(/No coverage is missing in latest changes/)
32
- message(report, sticky: sticky)
33
- else
32
+ if report.match(/some methods have no test coverage/)
34
33
  warn(report, sticky: sticky)
34
+ else
35
+ message(report, sticky: sticky)
35
36
  end
36
37
  end
37
38
 
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('spec_helper', __dir__)
4
+ require 'undercover/cli'
5
+
6
+ # rubocop:disable Metrics/BlockLength
7
+ module DangerUndercover
8
+ describe DangerUndercover::CLI do
9
+ let!(:mock_message) { 'Test Passed' }
10
+ let!(:directory) { File.join(Dir.getwd, 'coverage') } # default directory
11
+ let!(:file) { File.join(Dir.getwd, 'coverage/undercover.txt') } # default file
12
+
13
+ before(:each) do
14
+ # mocks the undercover #{args&.join(' ')} CLI command output.
15
+ allow(described_class).to receive(:`).and_return(mock_message)
16
+ end
17
+
18
+ after(:all) do
19
+ # removes the folder after tests pass.
20
+ FileUtils.rm_rf(File.join(Dir.getwd, 'coverage'))
21
+ end
22
+
23
+ it 'prints the undercover output' do
24
+ expect(described_class.run).to eql(mock_message)
25
+ end
26
+
27
+ it "creates a default folder if doesn't exists" do
28
+ FileUtils.rm_rf(directory)
29
+ described_class.run
30
+
31
+ expect(Dir.exist?(directory)).to be true
32
+ end
33
+
34
+ it 'creates default file undercover.txt' do
35
+ described_class.run
36
+
37
+ expect(File.exist?(file)).to be true
38
+ end
39
+
40
+ it 'writes undercover report to default file' do
41
+ described_class.run
42
+ report = File.open(file).read
43
+
44
+ expect(report).to eql(mock_message)
45
+ end
46
+ end
47
+ end
48
+ # rubocop:enable Metrics/BlockLength
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-undercover
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nimble
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-15 00:00:00.000000000 Z
12
+ date: 2020-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: danger-plugin-api
@@ -155,7 +155,8 @@ description: Show undercover report to PRs
155
155
  email:
156
156
  - dev@nimblehq.co
157
157
  - rafayet@nimblehq.co
158
- executables: []
158
+ executables:
159
+ - undercover-report
159
160
  extensions: []
160
161
  extra_rdoc_files: []
161
162
  files:
@@ -171,11 +172,14 @@ files:
171
172
  - LICENSE
172
173
  - README.md
173
174
  - Rakefile
175
+ - bin/undercover-report
174
176
  - danger-undercover.gemspec
175
177
  - lib/danger_plugin.rb
176
178
  - lib/danger_undercover.rb
179
+ - lib/undercover/cli.rb
177
180
  - lib/undercover/gem_version.rb
178
181
  - lib/undercover/plugin.rb
182
+ - spec/cli_spec.rb
179
183
  - spec/fixtures/undercover_failed.txt
180
184
  - spec/fixtures/undercover_passed.txt
181
185
  - spec/spec_helper.rb
@@ -204,6 +208,7 @@ signing_key:
204
208
  specification_version: 4
205
209
  summary: A Danger plugin for Undercover gem
206
210
  test_files:
211
+ - spec/cli_spec.rb
207
212
  - spec/fixtures/undercover_failed.txt
208
213
  - spec/fixtures/undercover_passed.txt
209
214
  - spec/spec_helper.rb