danger 5.2.1 → 5.2.2

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: d74236f8bd9ddb9051beca311ddb9f291dccfd8b
4
- data.tar.gz: 1165b856f1f001e97b853e57bb72ba9456d22dac
3
+ metadata.gz: 72f0e5d81fa65411996bf4e0ab4a5fbcf27ca666
4
+ data.tar.gz: 858ad689324e7f7ab3a63f0a12271d75eaf539e4
5
5
  SHA512:
6
- metadata.gz: ef9cd9ba1e8703321b2cad8750c904047b9aae5fbf5aadd2f25a23da14e73ed1a1a778a277cc653c7fdba6f0280d06d0858b02f0cf4252b09bddb85c971de07a
7
- data.tar.gz: 9558fcf118e4a16e7bf81baa81c10fc131eb8c0a37e125b8a1e515e4c1b47ab8adb17b0065a82812322421e672ebf2ade86c93c376c5b2eb456522e6419d8fc3
6
+ metadata.gz: 4539d2b0b778acf486d7daea6ff5e9624bcc4d50e8e26b2eb0a534bfc2acb5f9168d4c169f3e10af6f9c7dca21458415e2b0a9059f7dad76ce556a9664a4f4af
7
+ data.tar.gz: f2297c80d5e22a04954640ba16311b92bc229608532a12d41dc24aeebfbb2e9a957ed862192e285962f142c74023283b91bb2c0883fe30370db4e8fe7c528e4e
@@ -1,8 +1,11 @@
1
+ require "danger/helpers/array_subclass"
2
+
1
3
  module Danger
2
- class FileList < Array
4
+ class FileList
5
+ include Helpers::ArraySublcass
6
+
3
7
  # Information about pattern: http://ruby-doc.org/core-2.2.0/File.html#method-c-fnmatch
4
8
  # e.g. "**/something.*" for any file called something with any extension
5
-
6
9
  def include?(pattern)
7
10
  self.each do |current|
8
11
  return true if File.fnmatch(pattern, current)
@@ -0,0 +1,61 @@
1
+ module Danger
2
+ module Helpers
3
+ module ArraySublcass
4
+ include Comparable
5
+
6
+ def initialize(array)
7
+ @__array__ = array
8
+ end
9
+
10
+ def kind_of?(compare_class)
11
+ return true if compare_class == self.class
12
+
13
+ dummy.kind_of?(compare_class)
14
+ end
15
+
16
+ def method_missing(name, *args, &block)
17
+ super unless __array__.respond_to?(name)
18
+
19
+ respond_to_method(name, *args, &block)
20
+ end
21
+
22
+ def respond_to_missing?(name)
23
+ __array__.respond_to?(name) || super
24
+ end
25
+
26
+ def to_a
27
+ __array__
28
+ end
29
+
30
+ def to_ary
31
+ __array__
32
+ end
33
+
34
+ def <=>(other)
35
+ return unless other.kind_of?(self.class)
36
+
37
+ __array__ <=> other.instance_variable_get(:@__array__)
38
+ end
39
+
40
+ private
41
+
42
+ attr_accessor :__array__
43
+
44
+ def dummy
45
+ Class.new(Array).new
46
+ end
47
+
48
+ def respond_to_method(name, *args, &block)
49
+ result = __array__.send(name, *args, &block)
50
+ return result unless result.kind_of?(Array)
51
+
52
+ if name =~ /!/
53
+ __array__ = result
54
+ self
55
+ else
56
+ self.class.new(result)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -130,63 +130,67 @@ module Danger
130
130
  last_comment = editable_comments.last
131
131
  should_create_new_comment = new_comment || last_comment.nil?
132
132
 
133
- if should_create_new_comment
134
- previous_violations = {}
135
- else
136
- previous_violations = parse_comment(last_comment.body)
137
- end
133
+ previous_violations =
134
+ if should_create_new_comment
135
+ {}
136
+ else
137
+ parse_comment(last_comment.body)
138
+ end
138
139
 
139
- cmp = proc do |a, b|
140
- next -1 unless a.file
141
- next 1 unless b.file
140
+ regular_violations = regular_violations_group(
141
+ warnings: warnings,
142
+ errors: errors,
143
+ messages: messages,
144
+ markdowns: markdowns
145
+ )
142
146
 
143
- next a.line <=> b.line if a.file == b.file
144
- next a.file <=> b.file
145
- end
147
+ inline_violations = inline_violations_group(
148
+ warnings: warnings,
149
+ errors: errors,
150
+ messages: messages,
151
+ markdowns: markdowns
152
+ )
146
153
 
147
- # Sort to group inline comments by file
148
- # We copy because we need to mutate this arrays for inlines
149
- comment_warnings = warnings.sort(&cmp)
150
- comment_errors = errors.sort(&cmp)
151
- comment_messages = messages.sort(&cmp)
152
- comment_markdowns = markdowns.sort(&cmp)
153
-
154
- submit_inline_comments!(warnings: comment_warnings,
155
- errors: comment_errors,
156
- messages: comment_messages,
157
- markdowns: comment_markdowns,
158
- previous_violations: previous_violations,
159
- danger_id: danger_id)
160
-
161
- main_violations = comment_warnings + comment_errors + comment_messages + comment_markdowns
162
- if previous_violations.empty? && main_violations.empty?
154
+ rest_inline_violations = submit_inline_comments!({
155
+ danger_id: danger_id,
156
+ previous_violations: previous_violations
157
+ }.merge(inline_violations))
158
+
159
+ main_violations = merge_violations(
160
+ regular_violations, rest_inline_violations
161
+ )
162
+
163
+ main_violations_sum = main_violations.values.inject(:+)
164
+
165
+ if previous_violations.empty? && main_violations_sum.empty?
163
166
  # Just remove the comment, if there's nothing to say.
164
167
  delete_old_comments!(danger_id: danger_id)
165
168
  end
166
169
 
167
170
  # If there are still violations to show
168
- unless main_violations.empty?
169
- body = generate_comment(warnings: comment_warnings,
170
- errors: comment_errors,
171
- messages: comment_messages,
172
- markdowns: comment_markdowns,
173
- previous_violations: previous_violations,
174
- danger_id: danger_id,
175
- template: "github")
176
-
177
- if should_create_new_comment
178
- comment_result = client.add_comment(ci_source.repo_slug, ci_source.pull_request_id, body)
179
- else
180
- comment_result = client.update_comment(ci_source.repo_slug, last_comment.id, body)
181
- end
171
+ if main_violations_sum.any?
172
+ body = generate_comment({
173
+ template: "github",
174
+ danger_id: danger_id,
175
+ previous_violations: previous_violations
176
+ }.merge(main_violations))
177
+
178
+ comment_result =
179
+ if should_create_new_comment
180
+ client.add_comment(ci_source.repo_slug, ci_source.pull_request_id, body)
181
+ else
182
+ client.update_comment(ci_source.repo_slug, last_comment.id, body)
183
+ end
182
184
  end
183
185
 
184
186
  # Now, set the pull request status.
185
187
  # Note: this can terminate the entire process.
186
- submit_pull_request_status!(warnings: warnings,
187
- errors: errors,
188
- details_url: comment_result["html_url"],
189
- danger_id: danger_id)
188
+ submit_pull_request_status!(
189
+ warnings: warnings,
190
+ errors: errors,
191
+ details_url: comment_result["html_url"],
192
+ danger_id: danger_id
193
+ )
190
194
  end
191
195
 
192
196
  def submit_pull_request_status!(warnings: [], errors: [], details_url: [], danger_id: "danger")
@@ -234,17 +238,25 @@ module Danger
234
238
 
235
239
  def submit_inline_comments!(warnings: [], errors: [], messages: [], markdowns: [], previous_violations: [], danger_id: "danger")
236
240
  # Avoid doing any fetchs if there's no inline comments
237
- return if (warnings + errors + messages + markdowns).select(&:inline?).empty?
241
+ return {} if (warnings + errors + messages + markdowns).select(&:inline?).empty?
238
242
 
239
243
  diff_lines = self.pr_diff.lines
240
244
  pr_comments = client.pull_request_comments(ci_source.repo_slug, ci_source.pull_request_id)
241
245
  danger_comments = pr_comments.select { |comment| Comment.from_github(comment).generated_by_danger?(danger_id) }
242
246
  non_danger_comments = pr_comments - danger_comments
243
247
 
244
- submit_inline_comments_for_kind!("warning", warnings, diff_lines, danger_comments, previous_violations["warning"], danger_id: danger_id)
245
- submit_inline_comments_for_kind!("no_entry_sign", errors, diff_lines, danger_comments, previous_violations["error"], danger_id: danger_id)
246
- submit_inline_comments_for_kind!("book", messages, diff_lines, danger_comments, previous_violations["message"], danger_id: danger_id)
247
- submit_inline_comments_for_kind!(nil, markdowns, diff_lines, danger_comments, [], danger_id: danger_id)
248
+ warnings = submit_inline_comments_for_kind!(
249
+ "warning", warnings, diff_lines, danger_comments, previous_violations["warning"], danger_id: danger_id
250
+ )
251
+ errors = submit_inline_comments_for_kind!(
252
+ "no_entry_sign", errors, diff_lines, danger_comments, previous_violations["error"], danger_id: danger_id
253
+ )
254
+ messages = submit_inline_comments_for_kind!(
255
+ "book", messages, diff_lines, danger_comments, previous_violations["message"], danger_id: danger_id
256
+ )
257
+ markdowns = submit_inline_comments_for_kind!(
258
+ nil, markdowns, diff_lines, danger_comments, [], danger_id: danger_id
259
+ )
248
260
 
249
261
  # submit removes from the array all comments that are still in force
250
262
  # so we strike out all remaining ones
@@ -266,6 +278,13 @@ module Danger
266
278
  client.delete_pull_request_comment(ci_source.repo_slug, comment["id"]) if replies.empty?
267
279
  end
268
280
  end
281
+
282
+ {
283
+ warnings: warnings,
284
+ errors: errors,
285
+ messages: messages,
286
+ markdowns: markdowns
287
+ }
269
288
  end
270
289
 
271
290
  def messages_are_equivalent(m1, m2)
@@ -279,7 +298,7 @@ module Danger
279
298
  previous_violations ||= []
280
299
  is_markdown_content = emoji.nil?
281
300
 
282
- submit_inline = proc do |m|
301
+ messages.reject do |m|
283
302
  next false unless m.file && m.line
284
303
 
285
304
  position = find_position_in_diff diff_lines, m
@@ -328,8 +347,6 @@ module Danger
328
347
  # Remove this element from the array
329
348
  next true
330
349
  end
331
-
332
- messages.reject!(&submit_inline)
333
350
  end
334
351
 
335
352
  def find_position_in_diff(diff_lines, message)
@@ -430,6 +447,41 @@ module Danger
430
447
  @download_url = "https://raw.githubusercontent.com/#{organisation}/#{repository}/#{branch}/#{path}"
431
448
  end
432
449
  end
450
+
451
+ private
452
+
453
+ def regular_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
454
+ {
455
+ warnings: warnings.reject(&:inline?),
456
+ errors: errors.reject(&:inline?),
457
+ messages: messages.reject(&:inline?),
458
+ markdowns: markdowns.reject(&:inline?)
459
+ }
460
+ end
461
+
462
+ def inline_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
463
+ cmp = proc do |a, b|
464
+ next -1 unless a.file
465
+ next 1 unless b.file
466
+
467
+ next a.line <=> b.line if a.file == b.file
468
+ next a.file <=> b.file
469
+ end
470
+
471
+ # Sort to group inline comments by file
472
+ {
473
+ warnings: warnings.select(&:inline?).sort(&cmp),
474
+ errors: errors.select(&:inline?).sort(&cmp),
475
+ messages: messages.select(&:inline?).sort(&cmp),
476
+ markdowns: markdowns.select(&:inline?).sort(&cmp)
477
+ }
478
+ end
479
+
480
+ def merge_violations(*violation_groups)
481
+ violation_groups.inject({}) do |accumulator, group|
482
+ accumulator.merge(group) { |_, old, fresh| old + fresh }
483
+ end
484
+ end
433
485
  end
434
486
  end
435
487
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "5.2.1".freeze
2
+ VERSION = "5.2.2".freeze
3
3
  DESCRIPTION = "Like Unit Tests, but for your Team Culture.".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.1
4
+ version: 5.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orta Therox
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-09 00:00:00.000000000 Z
12
+ date: 2017-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -422,6 +422,7 @@ files:
422
422
  - lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb
423
423
  - lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb
424
424
  - lib/danger/danger_core/standard_error.rb
425
+ - lib/danger/helpers/array_subclass.rb
425
426
  - lib/danger/helpers/comment.rb
426
427
  - lib/danger/helpers/comments_helper.rb
427
428
  - lib/danger/helpers/comments_parsing_helper.rb