danger-code_coverage 0.0.2 → 1.0.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: f951b48390fd47e430b9454eeb47ed4194162c4d18b4fe1754ba9e808e38c271
4
- data.tar.gz: b542a4473db470c8d08560d8d8975fbfd434ec96868031283241cdd43653f064
3
+ metadata.gz: 87f7da211148028a249f9cc7c7148dbb062afff5f9051ab10a61f41f9ff099fb
4
+ data.tar.gz: 56e1a510efb6328c2503bfe5b2d8d692e47d7e41215ea7e8db94b5f0afb7a537
5
5
  SHA512:
6
- metadata.gz: de0610354f92718bcd63a2f97f8dafefd017d0ffb5d4620608ae1ddced52aaffcca0156eae6c12e94dfa2a6c99200cae87945a1f5f95dfc6b8af7d02b54dfedc
7
- data.tar.gz: 000ad24ce437e14e9db515e923c64312cc73ff9e34b0d7bd79e8c24753cfa207c06fbfd23451df073c3a731efcc99a188c62a50769c8e53cd83b36b2af4c8472
6
+ metadata.gz: 0be58244b5414e839169c53a33e08d2578baf4b6dc576584d9bd6a5e43fa7d186171b5d6588816b9c9150dda50e187c5916096330e719a6571b4a0ae50af78a1
7
+ data.tar.gz: 3bd3619c9e8c63258e40d955d05666d969c3bfb48e37816f29a37914957a8829fa39801d8512be2f769354b198618eccb247b1f15e2853947540fbcd40cfddcf
@@ -4,9 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [0.0.2] - 2019-6-22
8
- ### Changed
9
- - Search for files in subdirectories
7
+ ## [1.0.0] - 2019-6-26
8
+ ### Fixed
9
+ - Catch all errors while parsing url content
10
+
11
+ ### Added
12
+ - Sort options `:ascending`, `:descending`
10
13
 
11
14
  ## [0.0.1] - 2019-6-22
12
15
  ### Added
data/README.md CHANGED
@@ -97,8 +97,12 @@ This plugin is inspired and works only with the jenkins [code-coverage-api-plugi
97
97
  ## Usage
98
98
 
99
99
  code_coverage.report
100
+
101
+ ### Sort option
100
102
 
101
- ## Authentication
103
+ code_coverage.report(sort: :ascending)
104
+
105
+ ### Authentication
102
106
 
103
107
  If you run a jenkins server with required authentication you can pass them to `danger-code_coverage`.
104
108
  Create an API token with your CI user and do not pass normal password credentials.
@@ -15,7 +15,9 @@ module CodeCoverage
15
15
  raw_json =
16
16
  begin
17
17
  JSON.parse(content)
18
- rescue JSON::ParserError
18
+ # rubocop:disable Style/RescueStandardError
19
+ rescue
20
+ # rubocop:enable Style/RescueStandardError
19
21
  {}
20
22
  end
21
23
  parse_coverage(raw_json)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodeCoverage
4
- VERSION = '0.0.2'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -49,12 +49,22 @@ module Danger
49
49
  # @return [void]
50
50
  def report(*args)
51
51
  options = args.first
52
+ sort_order = options && options[:sort]
53
+ if sort_order && !sort_order.eql?(:ascending) && !sort_order.eql?(:descending)
54
+ raise(ArgumentError, 'Invalid configuration, use [:ascending, :descending]')
55
+ end
52
56
  check_auth(options)
53
57
 
54
58
  items = coverage_items
55
59
  items.select! { |item| file_in_changeset?(item.file) }
56
60
  items.each(&method(:update_item))
57
- items.sort_by! { |item| -item.total }
61
+ items.sort_by! do |item|
62
+ if sort_order.eql?(:ascending)
63
+ item.total
64
+ else
65
+ -item.total
66
+ end
67
+ end
58
68
  items.each(&method(:add_entry))
59
69
 
60
70
  return if @table.size.zero?
@@ -100,7 +100,7 @@ module Danger
100
100
  expect(entries[2]).to(eq('51.26'))
101
101
  end
102
102
 
103
- it 'sorts lines by total value descending' do
103
+ it 'sorts lines by total value descending as default' do
104
104
  mock_coverage_json('/assets/coverage_jacoco_multiple_unordered.json')
105
105
  mock_file_in_changeset(true)
106
106
 
@@ -117,6 +117,53 @@ module Danger
117
117
  expect(third[1]).to(include('MainActivity.java'))
118
118
  end
119
119
 
120
+ it 'sorts lines by total value descending with config' do
121
+ mock_coverage_json('/assets/coverage_jacoco_multiple_unordered.json')
122
+ mock_file_in_changeset(true)
123
+
124
+ @plugin.report(
125
+ sort: :descending
126
+ )
127
+ markdowns = @dangerfile.status_report[:markdowns]
128
+ expect(markdowns.length).to(be(1))
129
+ lines = markdowns.first.message.split("\n")
130
+ first = lines[4].split('|')
131
+ second = lines[5].split('|')
132
+ third = lines[6].split('|')
133
+
134
+ expect(first[1]).to(include('MainActivity2.java'))
135
+ expect(second[1]).to(include('MainActivity3.java'))
136
+ expect(third[1]).to(include('MainActivity.java'))
137
+ end
138
+
139
+ it 'sorts lines by total value ascending with config' do
140
+ mock_coverage_json('/assets/coverage_jacoco_multiple_unordered.json')
141
+ mock_file_in_changeset(true)
142
+
143
+ @plugin.report(
144
+ sort: :ascending
145
+ )
146
+ markdowns = @dangerfile.status_report[:markdowns]
147
+ expect(markdowns.length).to(be(1))
148
+ lines = markdowns.first.message.split("\n")
149
+ first = lines[4].split('|')
150
+ second = lines[5].split('|')
151
+ third = lines[6].split('|')
152
+
153
+ expect(first[1]).to(include('MainActivity.java'))
154
+ expect(second[1]).to(include('MainActivity3.java'))
155
+ expect(third[1]).to(include('MainActivity2.java'))
156
+ end
157
+
158
+ it 'throws error if sort config invalid' do
159
+ mock_coverage_json('/assets/coverage_jacoco_single.json')
160
+ expect {
161
+ @plugin.report(
162
+ sort: :invalid
163
+ )
164
+ }.to(raise_error(%r{:ascending, :descending}))
165
+ end
166
+
120
167
  it 'finds changed file in subdirectory' do
121
168
  mock_coverage_json('/assets/coverage_jacoco_single.json')
122
169
  mock_target_files(['src/main/java/com/example/kyaak/myapplication/MainActivity.java'])
@@ -137,13 +184,21 @@ module Danger
137
184
  markdowns = @dangerfile.status_report[:markdowns]
138
185
  expect(markdowns.length).to(be(0))
139
186
  end
187
+
188
+ it 'does not fail if request returns null' do
189
+ mock_coverage_json(nil)
190
+
191
+ @plugin.report
192
+ markdowns = @dangerfile.status_report[:markdowns]
193
+ expect(markdowns.length).to(be_zero)
194
+ end
140
195
  end
141
196
  end
142
197
  end
143
198
  end
144
199
 
145
200
  def mock_coverage_json(file)
146
- content = File.read(File.dirname(__FILE__) + file)
201
+ content = file ? File.read(File.dirname(__FILE__) + file) : file
147
202
  @plugin.stubs(:coverage_json).returns(content)
148
203
  end
149
204
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-code_coverage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyaak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-23 00:00:00.000000000 Z
11
+ date: 2019-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api