danger-simplecov_json 0.2.1 → 0.3.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
  SHA1:
3
- metadata.gz: 42faebe61519d4510608880949e1bf3c7fdd4411
4
- data.tar.gz: d63035f93c9833d773614eca933394ef7fdcd4e9
3
+ metadata.gz: 23beee17a6c7e4cc342988b1dafbcd6f5f01bd20
4
+ data.tar.gz: f79560aeb629c1f72e6bd7efe15ff249f6405a45
5
5
  SHA512:
6
- metadata.gz: 2e8a55c2370a34e3706ba120a7311a7a1f8ca13ec96cb7fd19acd7c305b022b87e6d30b8599a77741297b3d477c1627a260886387333460c6d04c3ee08c9e24a
7
- data.tar.gz: 7a00ab63e0c8e1e3f037aab861bbdd69036d25005990424f53a5b5ffaba0fadc1575a4bd8b17c68a1107ccf83422faebc374934a15a214da0a16bb9571dbfc35
6
+ metadata.gz: 77c49a651fcb90c278d9dd23c9c778652d384d8767ef74c41b83fc7075edc21036b57a833f1a9dd70b63220d025acfb9698a52f72942dac82065396d4493e923
7
+ data.tar.gz: 4e891b50fac5dfc9ff38a6c21bf841e888217cadbf48d551b5c34b8fb896ddb276837f3b4af7c28c43e4eff88ece90cda7f774b6ed1524b58d00a8fbfdefe01f
@@ -1,48 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-simplecov_json (0.2.0)
4
+ danger-simplecov_json (0.3.0)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.4.0)
10
+ addressable (2.5.0)
11
+ public_suffix (~> 2.0, >= 2.0.2)
11
12
  ast (2.3.0)
12
- claide (1.0.0)
13
- claide-plugins (0.9.1)
13
+ claide (1.0.1)
14
+ claide-plugins (0.9.2)
14
15
  cork
15
16
  nap
16
17
  open4 (~> 1.3)
17
18
  coderay (1.1.1)
18
19
  colored (1.2)
20
+ colored2 (3.1.2)
19
21
  cork (0.2.0)
20
22
  colored (~> 1.2)
21
- danger (3.2.1)
23
+ danger (4.2.2)
22
24
  claide (~> 1.0)
23
- claide-plugins (> 0.9.0)
24
- colored (~> 1.2)
25
+ claide-plugins (>= 0.9.2)
26
+ colored2 (~> 3.1)
25
27
  cork (~> 0.1)
26
28
  faraday (~> 0.9)
27
29
  faraday-http-cache (~> 1.0)
28
30
  git (~> 1)
29
- gitlab (~> 3.7.0)
30
31
  kramdown (~> 1.5)
31
32
  octokit (~> 4.2)
32
33
  terminal-table (~> 1)
33
34
  danger-plugin-api (1.0.0)
34
35
  danger (> 2.0)
35
36
  diff-lcs (1.2.5)
36
- faraday (0.9.2)
37
+ faraday (0.11.0)
37
38
  multipart-post (>= 1.2, < 3)
38
39
  faraday-http-cache (1.3.1)
39
40
  faraday (~> 0.8)
40
41
  ffi (1.9.14)
41
42
  formatador (0.2.5)
42
43
  git (1.3.0)
43
- gitlab (3.7.0)
44
- httparty (~> 0.13.0)
45
- terminal-table
46
44
  guard (2.14.0)
47
45
  formatador (>= 0.2.4)
48
46
  listen (>= 2.7, < 4.0)
@@ -57,25 +55,20 @@ GEM
57
55
  guard (~> 2.1)
58
56
  guard-compat (~> 1.1)
59
57
  rspec (>= 2.99.0, < 4.0)
60
- httparty (0.13.7)
61
- json (~> 1.8)
62
- multi_xml (>= 0.5.2)
63
- json (1.8.3)
64
- kramdown (1.12.0)
58
+ kramdown (1.13.2)
65
59
  listen (3.0.7)
66
60
  rb-fsevent (>= 0.9.3)
67
61
  rb-inotify (>= 0.9.7)
68
62
  lumberjack (1.0.10)
69
63
  method_source (0.8.2)
70
- multi_xml (0.5.5)
71
64
  multipart-post (2.0.0)
72
65
  nap (1.1.0)
73
66
  nenv (0.3.0)
74
67
  notiffany (0.1.0)
75
68
  nenv (~> 0.1)
76
69
  shellany (~> 0.0)
77
- octokit (4.3.0)
78
- sawyer (~> 0.7.0, >= 0.5.3)
70
+ octokit (4.6.2)
71
+ sawyer (~> 0.8.0, >= 0.5.3)
79
72
  open4 (1.3.4)
80
73
  parser (2.3.1.2)
81
74
  ast (~> 2.2)
@@ -84,6 +77,7 @@ GEM
84
77
  coderay (~> 1.1.0)
85
78
  method_source (~> 0.8.1)
86
79
  slop (~> 3.4)
80
+ public_suffix (2.0.5)
87
81
  rainbow (2.1.0)
88
82
  rake (10.5.0)
89
83
  rb-fsevent (0.9.7)
@@ -109,12 +103,13 @@ GEM
109
103
  ruby-progressbar (~> 1.7)
110
104
  unicode-display_width (~> 1.0, >= 1.0.1)
111
105
  ruby-progressbar (1.8.1)
112
- sawyer (0.7.0)
113
- addressable (>= 2.3.5, < 2.5)
114
- faraday (~> 0.8, < 0.10)
106
+ sawyer (0.8.1)
107
+ addressable (>= 2.3.5, < 2.6)
108
+ faraday (~> 0.8, < 1.0)
115
109
  shellany (0.0.1)
116
110
  slop (3.6.0)
117
- terminal-table (1.6.0)
111
+ terminal-table (1.7.0)
112
+ unicode-display_width (~> 1.1)
118
113
  thor (0.19.1)
119
114
  unicode-display_width (1.1.0)
120
115
  yard (0.8.7.6)
@@ -135,4 +130,4 @@ DEPENDENCIES
135
130
  yard (~> 0.8)
136
131
 
137
132
  BUNDLED WITH
138
- 1.12.5
133
+ 1.13.7
data/README.md CHANGED
@@ -52,6 +52,14 @@ You can also make the message not [sticky](http://danger.systems/reference.html)
52
52
  simplecov.report('coverage/coverage.json', sticky: false)
53
53
  ```
54
54
 
55
+ ### Individual File coverage
56
+
57
+ In addition, you can see coverage for the files you've added or modified in git:
58
+
59
+ ```ruby
60
+ simplecov.individual_report('coverage/coverage.json', Dir.pwd)
61
+ ```
62
+
55
63
  ## License
56
64
 
57
65
  MIT
@@ -1,3 +1,3 @@
1
1
  module SimpleCovJson
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -9,6 +9,7 @@ module Danger
9
9
  # @example Report code coverage
10
10
  #
11
11
  # simplecov.report('coverage/coverage.json')
12
+ # simplecov.individual_report('coverage/coverage.json', Dir.pwd)
12
13
  #
13
14
  # @see marcelofabri/danger-simplecov_json
14
15
  # @tags ruby, code-coverage, simplecov
@@ -33,6 +34,48 @@ module Danger
33
34
  end
34
35
  end
35
36
 
37
+ # Parse a JSON code coverage file and report on the files that you have
38
+ # added or modified in git
39
+ # @return [void]
40
+ #
41
+ def individual_report(coverage_path, current_project_path)
42
+ if File.exist? coverage_path
43
+ committed_files = git.modified_files + git.added_files
44
+
45
+ unless current_project_path.nil?
46
+ committed_files = committed_files.map do |s|
47
+ current_project_path + '/' + s
48
+ end
49
+ end
50
+
51
+ covered_files = JSON.parse(File.read(coverage_path), symbolize_names: true)[:files]
52
+ .select { |f| committed_files.include?(f[:filename]) }
53
+
54
+ return if covered_files.nil? || covered_files.empty?
55
+ markdown individual_coverage_message(covered_files)
56
+ else
57
+ fail('Code coverage data not found')
58
+ end
59
+ end
60
+
61
+ # Builds the markdown table displaying coverage on individual files
62
+ # @param [Array] covered_files
63
+ # @return [String] Markdown table
64
+ #
65
+ def individual_coverage_message(covered_files)
66
+ require 'terminal-table'
67
+
68
+ message = "### Code Coverage\n\n"
69
+ table = Terminal::Table.new(
70
+ headings: %w(File Coverage),
71
+ style: { border_i: '|' },
72
+ rows: covered_files.map do |file|
73
+ [file[:filename], "#{format('%.02f', file[:covered_percent])}%"]
74
+ end
75
+ ).to_s
76
+ message + table.split("\n")[1..-2].join("\n")
77
+ end
78
+
36
79
  def self.instance_name
37
80
  'simplecov'
38
81
  end
@@ -1,9 +1,10 @@
1
- {
1
+ {
2
2
  "timestamp":1471917899,
3
3
  "command_name":"RSpec",
4
- "files":[
4
+ "files":[
5
+ { "filename": "another_ruby_file.rb", "covered_percent": 20.0 }
5
6
  ],
6
- "metrics":{
7
+ "metrics":{
7
8
  "covered_percent":99.14754098360656,
8
9
  "covered_strength":31.564786885245905,
9
10
  "covered_lines":1512,
@@ -18,6 +18,17 @@ module Danger
18
18
  expect(@dangerfile.status_report[:messages]).to eq(['Code coverage is now at 99.15% (1512/1525 lines)'])
19
19
  end
20
20
 
21
+ it 'Shows individual code coverage report' do
22
+ allow(@simplecov.git).to receive(:added_files).and_return([])
23
+ allow(@simplecov.git).to receive(:modified_files)
24
+ .and_return(['another_ruby_file.rb'])
25
+
26
+ @simplecov.individual_report('spec/fixtures/coverage.json', nil)
27
+ expect(@dangerfile.status_report[:markdowns][0].message).to eq("### Code Coverage\n\n"\
28
+ "| File | Coverage |\n|----------------------|----------|\n"\
29
+ '| another_ruby_file.rb | 20.00% |')
30
+ end
31
+
21
32
  it 'Fails if code coverage not found' do
22
33
  @simplecov.report('spec/fixtures/missing_file.json')
23
34
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-simplecov_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Fabri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-14 00:00:00.000000000 Z
11
+ date: 2017-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  version: '0'
199
199
  requirements: []
200
200
  rubyforge_project:
201
- rubygems_version: 2.5.1
201
+ rubygems_version: 2.6.0
202
202
  signing_key:
203
203
  specification_version: 4
204
204
  summary: A Danger plugin to report code coverage generated by SimpleCov in JSON format.