danger 4.2.2 → 4.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: 04df75f0e2d2102ce7e9d3024be69a756881b387
4
- data.tar.gz: 76f1470a89a64bfb8b068ea8492b0a2f3c73bfa0
3
+ metadata.gz: 5e66eb8a455c065afa135919c09e81892a2fb371
4
+ data.tar.gz: c94bb59d445c9c37c840fb5cb3982870173f96eb
5
5
  SHA512:
6
- metadata.gz: 58f1c840ed23922d7d8124c32e86b95116551b882fd22dccd61576b8cc09055544b03c302cfbf08d98e01ae790ab4152a69d3668f39211c9a9ec6acbf220291a
7
- data.tar.gz: 525ee057e14c71dc46e95679c2d62686c6c48a507de94b9ed3202f738f78043d6ef27fc42543f3d69e48dfecff1441194ab7db5fb9f3c9903f56ed928412b179
6
+ metadata.gz: 82f6fe2e92a1ab9c069f86184768a9f78257e88a05e3a187057e685e7b05299db66adc773a76e074b34d688b01a7ceb53a3824ecc4e673510ee559dc13aef678
7
+ data.tar.gz: 5df07d5e39a8daf9463f872e17acd4e5e8ba0d818ddc8b0590919d0ea9a4344c22b8b87b63b46831f242653745566b16d7bba7921510679fc14b931ea75150f0
@@ -66,8 +66,8 @@ module Danger
66
66
  if repo_matches
67
67
  self.repo_slug = "#{repo_matches[1]}/#{repo_matches[2]}"
68
68
  else
69
- repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/.]+)(?:.git)?$})
70
- self.repo_slug = repo_matches[2] unless repo_matches.nil?
69
+ repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/]+)$})
70
+ self.repo_slug = repo_matches[2].gsub(/\.git$/, "") unless repo_matches.nil?
71
71
  end
72
72
  end
73
73
 
@@ -177,7 +177,7 @@ module Danger
177
177
 
178
178
  def uses_travis
179
179
  danger = "bundle exec danger".yellow
180
- config = YAML.load(File.read(".travis.yml"))
180
+ config = YAML.load(File.read(".travis.yml")) # rubocop:disable Security/YAMLLoad
181
181
  if config.kind_of?(Hash) && config["script"]
182
182
  ui.say "Add " + "- ".yellow + danger + " as a new step in the " + "script".yellow + " section of your .travis.yml file."
183
183
  else
@@ -190,7 +190,7 @@ module Danger
190
190
 
191
191
  def uses_circle
192
192
  danger = "- bundle exec danger".yellow
193
- config = YAML.load(File.read("circle.yml"))
193
+ config = YAML.load(File.read("circle.yml")) # rubocop:disable Security/YAMLLoad
194
194
 
195
195
  if config.kind_of?(Hash) && config["test"]
196
196
  if config["test"]["post"]
@@ -20,9 +20,15 @@ module Danger
20
20
  end
21
21
 
22
22
  def initialize(argv)
23
+ show_help = true if argv.arguments == ["-h"]
24
+
23
25
  @pr_num = argv.option("use-merged-pr")
24
26
  @clear_http_cache = argv.flag?("clear-http-cache", false)
25
27
 
28
+ # Currently CLAide doesn't support short option like -h https://github.com/CocoaPods/CLAide/pull/60
29
+ # when user pass in -h, mimic the behavior of passing in --help.
30
+ argv = CLAide::ARGV.new ["--help"] if show_help
31
+
26
32
  super
27
33
 
28
34
  if argv.flag?("pry", false)
@@ -19,10 +19,16 @@ module Danger
19
19
  end
20
20
 
21
21
  def initialize(argv)
22
+ show_help = true if argv.arguments == ["-h"]
23
+
22
24
  @pr_url = argv.shift_argument
23
25
  @clear_http_cache = argv.flag?("clear-http-cache", false)
24
26
  dangerfile = argv.option("dangerfile", "Dangerfile")
25
27
 
28
+ # Currently CLAide doesn't support short option like -h https://github.com/CocoaPods/CLAide/pull/60
29
+ # when user pass in -h, mimic the behavior of passing in --help.
30
+ argv = CLAide::ARGV.new ["--help"] if show_help
31
+
26
32
  super
27
33
 
28
34
  @dangerfile_path = dangerfile if File.exist?(dangerfile)
@@ -224,6 +224,16 @@ module Danger
224
224
  paths.first(paths.count - 1).join(", ") + " & " + paths.last
225
225
  end
226
226
 
227
+ # @!group GitHub Misc
228
+ # Use to ignore inline messages which lay outside a diff's range, thereby not posting them in the main comment.
229
+ # @param [Bool] dismiss
230
+ # Ignore out of range inline messages, defaults to `true`
231
+ #
232
+ # @return [void]
233
+ def dismiss_out_of_range_messages(dismiss: true)
234
+ @github.dismiss_out_of_range_messages = dismiss == true
235
+ end
236
+
227
237
  [:title, :body, :author, :labels, :json].each do |suffix|
228
238
  alias_method "mr_#{suffix}".to_sym, "pr_#{suffix}".to_sym
229
239
  end
@@ -16,6 +16,9 @@ module Danger
16
16
  # via the return value for the danger command. If you have linters with errors for this call
17
17
  # you can use `messaging.fail` instead.
18
18
  #
19
+ # You can optionally add `file` and `line` to provide inline feedback on a PR in GitHub, note that
20
+ # only feedback inside the PR's diff will show up inline. Others will appear inside the main comment.
21
+ #
19
22
  # It is possible to have Danger ignore specific warnings or errors by writing `Danger: Ignore "[warning/error text]"`.
20
23
  #
21
24
  # Sidenote: Messaging is the only plugin which adds functions to the root of the Dangerfile.
@@ -12,7 +12,7 @@ module Danger
12
12
  class GitHub < RequestSource
13
13
  include Danger::Helpers::CommentsHelper
14
14
 
15
- attr_accessor :pr_json, :issue_json, :support_tokenless_auth
15
+ attr_accessor :pr_json, :issue_json, :support_tokenless_auth, :dismiss_out_of_range_messages
16
16
 
17
17
  def self.env_vars
18
18
  ["DANGER_GITHUB_API_TOKEN"]
@@ -26,6 +26,7 @@ module Danger
26
26
  self.ci_source = ci_source
27
27
  self.environment = environment
28
28
  self.support_tokenless_auth = false
29
+ self.dismiss_out_of_range_messages = false
29
30
 
30
31
  @token = @environment["DANGER_GITHUB_API_TOKEN"]
31
32
  end
@@ -134,12 +135,6 @@ module Danger
134
135
  previous_violations = parse_comment(last_comment.body)
135
136
  end
136
137
 
137
- main_violations = (warnings + errors + messages + markdowns).reject(&:inline?)
138
- if previous_violations.empty? && main_violations.empty?
139
- # Just remove the comment, if there's nothing to say.
140
- delete_old_comments!(danger_id: danger_id)
141
- end
142
-
143
138
  cmp = proc do |a, b|
144
139
  next -1 unless a.file
145
140
  next 1 unless b.file
@@ -162,6 +157,12 @@ module Danger
162
157
  previous_violations: previous_violations,
163
158
  danger_id: danger_id)
164
159
 
160
+ main_violations = comment_warnings + comment_errors + comment_messages + comment_markdowns
161
+ if previous_violations.empty? && main_violations.empty?
162
+ # Just remove the comment, if there's nothing to say.
163
+ delete_old_comments!(danger_id: danger_id)
164
+ end
165
+
165
166
  # If there are still violations to show
166
167
  unless main_violations.empty?
167
168
  body = generate_comment(warnings: comment_warnings,
@@ -232,7 +233,7 @@ module Danger
232
233
 
233
234
  def submit_inline_comments!(warnings: [], errors: [], messages: [], markdowns: [], previous_violations: [], danger_id: "danger")
234
235
  # Avoid doing any fetchs if there's no inline comments
235
- return if (warnings + errors + messages).select(&:inline?).empty?
236
+ return if (warnings + errors + messages + markdowns).select(&:inline?).empty?
236
237
 
237
238
  diff_lines = self.pr_diff.lines
238
239
  pr_comments = client.pull_request_comments(ci_source.repo_slug, ci_source.pull_request_id)
@@ -282,8 +283,8 @@ module Danger
282
283
 
283
284
  position = find_position_in_diff diff_lines, m
284
285
 
285
- # Keep the change if it's line is not in the diff
286
- next false if position.nil?
286
+ # Keep the change if it's line is not in the diff and not in dismiss mode
287
+ next self.dismiss_out_of_range_messages if position.nil?
287
288
 
288
289
  # Once we know we're gonna submit it, we format it
289
290
  if is_markdown_content
@@ -332,7 +333,7 @@ module Danger
332
333
 
333
334
  def find_position_in_diff(diff_lines, message)
334
335
  range_header_regexp = /@@ -([0-9]+),([0-9]+) \+(?<start>[0-9]+)(,(?<end>[0-9]+))? @@.*/
335
- file_header_regexp = %r{ a/.*}
336
+ file_header_regexp = %r{^diff --git a/.*}
336
337
 
337
338
  pattern = "+++ b/" + message.file + "\n"
338
339
  file_start = diff_lines.index(pattern)
@@ -343,6 +344,9 @@ module Danger
343
344
  file_line = nil
344
345
 
345
346
  diff_lines.drop(file_start).each do |line|
347
+ # If we found the start of another file diff, we went too far
348
+ break if line.match file_header_regexp
349
+
346
350
  match = line.match range_header_regexp
347
351
 
348
352
  # file_line is set once we find the hunk the line is in
@@ -359,9 +363,6 @@ module Danger
359
363
 
360
364
  next unless match
361
365
 
362
- # If we found the start of another file diff, we went too far
363
- break if line.match file_header_regexp
364
-
365
366
  range_start = match[:start].to_i
366
367
  if match[:end]
367
368
  range_end = match[:end].to_i + range_start
@@ -381,7 +382,7 @@ module Danger
381
382
 
382
383
  # See the tests for examples of data coming in looks like
383
384
  def parse_message_from_row(row)
384
- message_regexp = %r{(<(a |span data-)href="https://github.com/#{ci_source.repo_slug}/blob/[0-9a-z]+/(?<file>[^#]+)#L(?<line>[0-9]+)"(>[^<]*</a> - |/>))?(?<message>.*?)}im
385
+ message_regexp = %r{(<(a |span data-)href="https://#{host}/#{ci_source.repo_slug}/blob/[0-9a-z]+/(?<file>[^#]+)#L(?<line>[0-9]+)"(>[^<]*</a> - |/>))?(?<message>.*?)}im
385
386
  match = message_regexp.match(row)
386
387
 
387
388
  if match[:line]
@@ -393,7 +394,7 @@ module Danger
393
394
  end
394
395
 
395
396
  def markdown_link_to_message(message, hide_link)
396
- url = "https://github.com/#{ci_source.repo_slug}/blob/#{pr_json['head']['sha']}/#{message.file}#L#{message.line}"
397
+ url = "https://#{host}/#{ci_source.repo_slug}/blob/#{pr_json['head']['sha']}/#{message.file}#L#{message.line}"
397
398
 
398
399
  if hide_link
399
400
  "<span data-href=\"#{url}\"/>"
@@ -66,22 +66,18 @@ module Danger
66
66
 
67
67
  def mr_comments
68
68
  @comments ||= begin
69
- client.merge_request_comments(escaped_ci_slug, ci_source.pull_request_id)
69
+ client.merge_request_comments(ci_source.repo_slug, ci_source.pull_request_id)
70
70
  .map { |comment| Comment.from_gitlab(comment) }
71
71
  end
72
72
  end
73
73
 
74
74
  def mr_diff
75
75
  @mr_diff ||= begin
76
- client.merge_request_changes(escaped_ci_slug, ci_source.pull_request_id)
76
+ client.merge_request_changes(ci_source.repo_slug, ci_source.pull_request_id)
77
77
  .changes.map { |change| change["diff"] }.join("\n")
78
78
  end
79
79
  end
80
80
 
81
- def escaped_ci_slug
82
- @escaped_ci_slug ||= CGI.escape(ci_source.repo_slug)
83
- end
84
-
85
81
  def setup_danger_branches
86
82
  head_commit = self.scm.head_commit
87
83
 
@@ -96,8 +92,8 @@ module Danger
96
92
  end
97
93
 
98
94
  def fetch_details
99
- self.mr_json = client.merge_request(escaped_ci_slug, self.ci_source.pull_request_id)
100
- self.commits_json = client.merge_request_commits(escaped_ci_slug, self.ci_source.pull_request_id)
95
+ self.mr_json = client.merge_request(ci_source.repo_slug, self.ci_source.pull_request_id)
96
+ self.commits_json = client.merge_request_commits(ci_source.repo_slug, self.ci_source.pull_request_id)
101
97
  self.ignored_violations = ignored_violations_from_pr
102
98
  end
103
99
 
@@ -131,12 +127,12 @@ module Danger
131
127
 
132
128
  if editable_comments.empty?
133
129
  client.create_merge_request_comment(
134
- escaped_ci_slug, ci_source.pull_request_id, body
130
+ ci_source.repo_slug, ci_source.pull_request_id, body
135
131
  )
136
132
  else
137
133
  original_id = editable_comments.first.id
138
134
  client.edit_merge_request_comment(
139
- escaped_ci_slug, ci_source.pull_request_id, original_id, body
135
+ ci_source.repo_slug, ci_source.pull_request_id, original_id, body
140
136
  )
141
137
  end
142
138
  end
@@ -147,7 +143,7 @@ module Danger
147
143
  next unless comment.generated_by_danger?(danger_id)
148
144
  next if comment.id == except
149
145
  client.delete_merge_request_comment(
150
- escaped_ci_slug,
146
+ ci_source.repo_slug,
151
147
  ci_source.pull_request_id,
152
148
  comment.id
153
149
  )
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "4.2.2".freeze
2
+ VERSION = "4.3.0".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: 4.2.2
4
+ version: 4.3.0
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-02-14 00:00:00.000000000 Z
12
+ date: 2017-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -465,7 +465,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
465
465
  version: '0'
466
466
  requirements: []
467
467
  rubyforge_project:
468
- rubygems_version: 2.2.2
468
+ rubygems_version: 2.5.2
469
469
  signing_key:
470
470
  specification_version: 4
471
471
  summary: Like Unit Tests, but for your Team Culture.