danger 8.4.2 → 9.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +1 -1
  4. data/bin/danger +1 -1
  5. data/lib/danger/ci_source/appcircle.rb +83 -0
  6. data/lib/danger/ci_source/appveyor.rb +1 -0
  7. data/lib/danger/ci_source/azure_pipelines.rb +20 -5
  8. data/lib/danger/ci_source/bamboo.rb +1 -1
  9. data/lib/danger/ci_source/bitbucket_pipelines.rb +1 -2
  10. data/lib/danger/ci_source/bitrise.rb +10 -10
  11. data/lib/danger/ci_source/buildkite.rb +1 -1
  12. data/lib/danger/ci_source/circle.rb +1 -1
  13. data/lib/danger/ci_source/circle_api.rb +2 -2
  14. data/lib/danger/ci_source/code_build.rb +20 -6
  15. data/lib/danger/ci_source/codefresh.rb +7 -13
  16. data/lib/danger/ci_source/concourse.rb +4 -5
  17. data/lib/danger/ci_source/dotci.rb +4 -6
  18. data/lib/danger/ci_source/github_actions.rb +6 -6
  19. data/lib/danger/ci_source/gitlab_ci.rb +13 -19
  20. data/lib/danger/ci_source/jenkins.rb +22 -23
  21. data/lib/danger/ci_source/local_git_repo.rb +36 -38
  22. data/lib/danger/ci_source/local_only_git_repo.rb +5 -8
  23. data/lib/danger/ci_source/support/find_repo_info_from_url.rb +11 -10
  24. data/lib/danger/ci_source/support/pull_request_finder.rb +47 -43
  25. data/lib/danger/ci_source/teamcity.rb +1 -1
  26. data/lib/danger/ci_source/xcode_cloud.rb +7 -7
  27. data/lib/danger/commands/init.rb +1 -1
  28. data/lib/danger/commands/local.rb +1 -1
  29. data/lib/danger/commands/local_helpers/http_cache.rb +2 -0
  30. data/lib/danger/commands/local_helpers/local_setup.rb +2 -0
  31. data/lib/danger/commands/local_helpers/pry_setup.rb +1 -0
  32. data/lib/danger/commands/plugins/plugin_json.rb +1 -3
  33. data/lib/danger/commands/plugins/plugin_lint.rb +0 -2
  34. data/lib/danger/commands/plugins/plugin_readme.rb +2 -5
  35. data/lib/danger/commands/pr.rb +2 -1
  36. data/lib/danger/commands/runner.rb +1 -1
  37. data/lib/danger/commands/staging.rb +7 -7
  38. data/lib/danger/commands/systems.rb +4 -6
  39. data/lib/danger/comment_generators/gitlab_inline.md.erb +1 -1
  40. data/lib/danger/comment_generators/vsts_inline.md.erb +17 -0
  41. data/lib/danger/core_ext/file_list.rb +2 -2
  42. data/lib/danger/danger_core/dangerfile.rb +19 -16
  43. data/lib/danger/danger_core/environment_manager.rb +2 -1
  44. data/lib/danger/danger_core/executor.rb +10 -11
  45. data/lib/danger/danger_core/message_aggregator.rb +1 -0
  46. data/lib/danger/danger_core/messages/base.rb +1 -0
  47. data/lib/danger/danger_core/messages/markdown.rb +3 -4
  48. data/lib/danger/danger_core/messages/violation.rb +1 -2
  49. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +1 -3
  50. data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +4 -4
  51. data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +9 -3
  52. data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +4 -3
  53. data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +3 -1
  54. data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +3 -1
  55. data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +4 -3
  56. data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +3 -1
  57. data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +3 -3
  58. data/lib/danger/danger_core/standard_error.rb +2 -3
  59. data/lib/danger/helpers/array_subclass.rb +2 -2
  60. data/lib/danger/helpers/comments_helper.rb +8 -7
  61. data/lib/danger/helpers/comments_parsing_helper.rb +3 -2
  62. data/lib/danger/helpers/emoji_mapper.rb +1 -1
  63. data/lib/danger/plugin_support/plugin.rb +0 -1
  64. data/lib/danger/plugin_support/plugin_linter.rb +1 -0
  65. data/lib/danger/request_sources/bitbucket_cloud.rb +3 -6
  66. data/lib/danger/request_sources/bitbucket_cloud_api.rb +5 -7
  67. data/lib/danger/request_sources/bitbucket_server.rb +47 -11
  68. data/lib/danger/request_sources/bitbucket_server_api.rb +17 -14
  69. data/lib/danger/request_sources/code_insights_api.rb +9 -14
  70. data/lib/danger/request_sources/github/github.rb +30 -38
  71. data/lib/danger/request_sources/github/github_review.rb +3 -2
  72. data/lib/danger/request_sources/github/github_review_resolver.rb +0 -2
  73. data/lib/danger/request_sources/github/github_review_unsupported.rb +0 -2
  74. data/lib/danger/request_sources/gitlab.rb +53 -75
  75. data/lib/danger/request_sources/local_only.rb +1 -4
  76. data/lib/danger/request_sources/request_source.rb +20 -8
  77. data/lib/danger/request_sources/support/get_ignored_violation.rb +1 -1
  78. data/lib/danger/request_sources/vsts.rb +175 -15
  79. data/lib/danger/request_sources/vsts_api.rb +41 -7
  80. data/lib/danger/scm_source/git_repo.rb +2 -1
  81. data/lib/danger/version.rb +1 -1
  82. data/lib/danger.rb +1 -0
  83. metadata +39 -37
  84. data/lib/danger/ci_source/vsts.rb +0 -73
@@ -60,7 +60,6 @@ module Danger
60
60
  # When an undefined method is called, we check to see if it's something
61
61
  # that the core DSLs have, then starts looking at plugins support.
62
62
 
63
- # rubocop:disable Style/MethodMissing
64
63
  def method_missing(method_sym, *arguments, **keyword_arguments, &_block)
65
64
  @core_plugins.each do |plugin|
66
65
  if plugin.public_methods(false).include?(method_sym)
@@ -97,6 +96,7 @@ module Danger
97
96
  plugins = Plugin.all_plugins
98
97
  plugins.each do |klass|
99
98
  next if klass.respond_to?(:singleton_class?) && klass.singleton_class?
99
+
100
100
  plugin = klass.new(self)
101
101
  next if plugin.nil? || @plugins[klass]
102
102
 
@@ -115,7 +115,7 @@ module Danger
115
115
  end
116
116
 
117
117
  def external_dsl_attributes
118
- plugins.values.reject { |plugin| @core_plugins.include? plugin } .map { |plugin| { plugin: plugin, methods: plugin.public_methods(false) } }
118
+ plugins.values.reject { |plugin| @core_plugins.include? plugin }.map { |plugin| { plugin: plugin, methods: plugin.public_methods(false) } }
119
119
  end
120
120
 
121
121
  def method_values_for_plugin_hashes(plugin_hashes)
@@ -200,12 +200,12 @@ module Danger
200
200
  self.defined_in_file = path
201
201
  instance_eval do
202
202
  # rubocop:disable Lint/RescueException
203
- begin
204
- eval_file(contents, path)
205
- rescue Exception => e
206
- message = "Invalid `#{path.basename}` file: #{e.message}"
207
- raise DSLError.new(message, path, e.backtrace, contents)
208
- end
203
+
204
+ eval_file(contents, path)
205
+ rescue Exception => e
206
+ message = "Invalid `#{path.basename}` file: #{e.message}"
207
+ raise DSLError.new(message, path, e.backtrace, contents)
208
+
209
209
  # rubocop:enable Lint/RescueException
210
210
  end
211
211
  end
@@ -257,9 +257,9 @@ module Danger
257
257
 
258
258
  if env.request_source.respond_to?(:update_pr_by_line!) && ENV["DANGER_MESSAGE_AGGREGATION"]
259
259
  env.request_source.update_pr_by_line!(message_groups: MessageAggregator.aggregate(**report),
260
- new_comment: new_comment,
261
- remove_previous_comments: remove_previous_comments,
262
- danger_id: report[:danger_id])
260
+ new_comment: new_comment,
261
+ remove_previous_comments: remove_previous_comments,
262
+ danger_id: report[:danger_id])
263
263
  else
264
264
  env.request_source.update_pull_request!(
265
265
  **report,
@@ -274,7 +274,7 @@ module Danger
274
274
  env.scm.diff_for_folder(".".freeze, from: base_branch, to: head_branch, lookup_top_level: true)
275
275
  end
276
276
 
277
- def run(base_branch, head_branch, dangerfile_path, danger_id, new_comment, remove_previous_comments)
277
+ def run(base_branch, head_branch, dangerfile_path, danger_id, new_comment, remove_previous_comments, report_results = true)
278
278
  # Setup internal state
279
279
  init_plugins
280
280
  env.fill_environment_vars
@@ -289,13 +289,13 @@ module Danger
289
289
  # Push results to the API
290
290
  # Pass along the details of the run to the request source
291
291
  # to send back to the code review site.
292
- post_results(danger_id, new_comment, remove_previous_comments) unless danger_id.nil?
292
+ post_results(danger_id, new_comment, remove_previous_comments) if report_results
293
293
 
294
294
  # Print results in the terminal
295
295
  print_results
296
- rescue DSLError => ex
296
+ rescue DSLError => e
297
297
  # Push exception to the API and re-raise
298
- post_exception(ex, danger_id, new_comment) unless danger_id.nil?
298
+ post_exception(e, danger_id, new_comment) unless danger_id.nil?
299
299
  raise
300
300
  ensure
301
301
  # Makes sure that Danger specific git branches are cleaned
@@ -308,7 +308,7 @@ module Danger
308
308
  private
309
309
 
310
310
  def eval_file(contents, path)
311
- eval(contents, nil, path.to_s) # rubocop:disable Eval
311
+ eval(contents, nil, path.to_s) # rubocop:disable Security/Eval
312
312
  end
313
313
 
314
314
  def print_list(title, rows)
@@ -335,6 +335,9 @@ module Danger
335
335
  end
336
336
 
337
337
  def post_exception(ex, danger_id, new_comment)
338
+ return if ENV["DANGER_DO_NOT_POST_INVALID_DANGERFILE_ERROR"]
339
+ return if danger_id.nil?
340
+
338
341
  env.request_source.update_pull_request!(
339
342
  danger_id: danger_id,
340
343
  new_comment: new_comment,
@@ -37,6 +37,7 @@ module Danger
37
37
  request_source = klass.new(self.ci_source, env)
38
38
  next unless request_source.validates_as_ci?
39
39
  next unless request_source.validates_as_api_source?
40
+
40
41
  self.request_source = request_source
41
42
  end
42
43
 
@@ -90,7 +91,7 @@ module Danger
90
91
  RequestSources::GitLab
91
92
  elsif repo_url =~ /bitbucket\.(org|com)/i
92
93
  RequestSources::BitbucketCloud
93
- elsif repo_url =~ /dev\.azure\.com/i
94
+ elsif repo_url =~ /\.visualstudio\.com/i || repo_url =~ /dev\.azure\.com/i
94
95
  RequestSources::VSTS
95
96
  end
96
97
  end
@@ -25,16 +25,14 @@ module Danger
25
25
  env ||= EnvironmentManager.new(system_env, cork, danger_id)
26
26
  dm ||= Dangerfile.new(env, cork)
27
27
 
28
- ran_status = begin
29
- dm.run(
30
- base_branch(base),
31
- head_branch(head),
32
- dangerfile_path,
33
- danger_id,
34
- new_comment,
35
- remove_previous_comments
36
- )
37
- end
28
+ ran_status = dm.run(
29
+ base_branch(base),
30
+ head_branch(head),
31
+ dangerfile_path,
32
+ danger_id,
33
+ new_comment,
34
+ remove_previous_comments
35
+ )
38
36
 
39
37
  # By default Danger will use the status API to fail a build,
40
38
  # allowing execution to continue, this behavior isn't always
@@ -85,7 +83,8 @@ module Danger
85
83
  end
86
84
 
87
85
  def commit_request(ci_name)
88
- return "Merge Request" if ci_name == 'GitLabCI'
86
+ return "Merge Request" if ci_name == "GitLabCI"
87
+
89
88
  return "Pull Request"
90
89
  end
91
90
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "danger/danger_core/message_group"
3
4
  require "danger/helpers/message_groups_array_helper"
4
5
 
@@ -21,6 +21,7 @@ module Danger
21
21
 
22
22
  line <=> other.line
23
23
  end
24
+
24
25
  # compares a and b based entirely on whether one or the other is nil
25
26
  # arguments are in the same order as `a <=> b`
26
27
  # nil is sorted earlier - so cmp_nils(nil, 1) => -1
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "danger/danger_core/messages/base"
3
4
 
4
5
  module Danger
5
6
  class Markdown < BaseMessage
6
-
7
7
  def initialize(message, file = nil, line = nil)
8
8
  super(type: :markdown, message: message, file: file, line: line)
9
9
  end
@@ -21,8 +21,7 @@ module Danger
21
21
  h = 1
22
22
  h = h * 31 + message.hash
23
23
  h = h * 17 + file.hash
24
- h = h * 17 + line.hash
25
- h
24
+ h * 17 + line.hash
26
25
  end
27
26
 
28
27
  def to_s
@@ -30,7 +29,7 @@ module Danger
30
29
  extra << "file: #{file}" unless file
31
30
  extra << "line: #{line}" unless line
32
31
 
33
- "Markdown #{message} { #{extra.join ', '.freeze} }"
32
+ "Markdown #{message} { #{extra.join ', '} }"
34
33
  end
35
34
 
36
35
  def <=>(other)
@@ -29,8 +29,7 @@ module Danger
29
29
  h = h * 31 + message.hash
30
30
  h = h * 13 + sticky.hash
31
31
  h = h * 17 + file.hash
32
- h = h * 17 + line.hash
33
- h
32
+ h * 17 + line.hash
34
33
  end
35
34
 
36
35
  def <=>(other)
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  require "danger/plugin_support/plugin"
4
2
 
5
3
  module Danger
@@ -52,6 +50,7 @@ module Danger
52
50
  # So that this init can fail.
53
51
  def self.new(dangerfile)
54
52
  return nil if dangerfile.env.request_source.class != Danger::RequestSources::BitbucketCloud
53
+
55
54
  super
56
55
  end
57
56
 
@@ -139,6 +138,5 @@ module Danger
139
138
  def head_commit
140
139
  @bs.pr_json[:source][:commit][:hash]
141
140
  end
142
-
143
141
  end
144
142
  end
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  require "danger/plugin_support/plugin"
4
2
 
5
3
  module Danger
@@ -52,6 +50,7 @@ module Danger
52
50
  # So that this init can fail.
53
51
  def self.new(dangerfile)
54
52
  return nil if dangerfile.env.request_source.class != Danger::RequestSources::BitbucketServer
53
+
55
54
  super
56
55
  end
57
56
 
@@ -169,7 +168,7 @@ module Danger
169
168
  def markdown_link(paths, full_path: true)
170
169
  create_link(paths, full_path) { |href, text| create_markdown_link(href, text) }
171
170
  end
172
-
171
+
173
172
  # @!group Bitbucket Server Misc
174
173
  # Updates the PR with build status and build server job link.
175
174
  # @param [String] status
@@ -181,7 +180,7 @@ module Danger
181
180
  # @return [String]
182
181
  #
183
182
  def update_pr_build_status(status, build_job_link, description)
184
- @bs.update_pr_build_status(status, build_job_link, description)
183
+ @bs.update_pr_build_status(status, build_job_link, description)
185
184
  end
186
185
 
187
186
  private
@@ -201,6 +200,7 @@ module Danger
201
200
  end
202
201
 
203
202
  return paths.first if paths.count < 2
203
+
204
204
  paths.first(paths.count - 1).join(", ") + " & " + paths.last
205
205
  end
206
206
 
@@ -74,6 +74,8 @@ module Danger
74
74
  # @option opts [String] :github GitHub repo
75
75
  # @option opts [String] :gitlab GitLab repo
76
76
  # @option opts [String] :gem Gem name
77
+ # @option opts [String] :ref The name of branch, tag or commit
78
+ # @option opts [String] :branch Alias of :ref
77
79
  # @option opts [String] :path Path to Dangerfile
78
80
  # @return [void]
79
81
  def import_dangerfile(opts)
@@ -82,9 +84,9 @@ module Danger
82
84
  import_dangerfile_from_github(opts)
83
85
  elsif opts.kind_of?(Hash)
84
86
  if opts.key?(:github)
85
- import_dangerfile_from_github(opts[:github], opts[:branch], opts[:path])
87
+ import_dangerfile_from_github(opts[:github], opts[:ref] || opts[:branch], opts[:path])
86
88
  elsif opts.key?(:gitlab)
87
- import_dangerfile_from_gitlab(opts[:gitlab], opts[:branch], opts[:path])
89
+ import_dangerfile_from_gitlab(opts[:gitlab], opts[:ref] || opts[:branch], opts[:path])
88
90
  elsif opts.key?(:path)
89
91
  import_dangerfile_from_path(opts[:path])
90
92
  elsif opts.key?(:gem)
@@ -132,7 +134,8 @@ module Danger
132
134
  #
133
135
  def import_dangerfile_from_path(path)
134
136
  raise "`import_dangerfile_from_path` requires a string" unless path.kind_of?(String)
135
- local_path = File.join(path, "Dangerfile")
137
+
138
+ local_path = File.file?(path) ? path : File.join(path, "Dangerfile")
136
139
  @dangerfile.parse(Pathname.new(local_path))
137
140
  end
138
141
 
@@ -145,6 +148,7 @@ module Danger
145
148
  #
146
149
  def import_dangerfile_from_gem(name)
147
150
  raise "`import_dangerfile_from_gem` requires a string" unless name.kind_of?(String)
151
+
148
152
  spec = Gem::Specification.find_by_name(name)
149
153
  import_dangerfile_from_path(spec.gem_dir)
150
154
  rescue Gem::MissingSpecError
@@ -164,6 +168,7 @@ module Danger
164
168
  #
165
169
  def import_dangerfile_from_github(slug, branch = nil, path = nil)
166
170
  raise "`import_dangerfile_from_github` requires a string" unless slug.kind_of?(String)
171
+
167
172
  org, repo = slug.split("/")
168
173
  download_url = env.request_source.file_url(organisation: org, repository: repo, branch: branch, path: path || "Dangerfile")
169
174
  local_path = download(download_url)
@@ -196,6 +201,7 @@ module Danger
196
201
  #
197
202
  def import_dangerfile_from_url(url)
198
203
  raise "`import_dangerfile_from_url` requires a string" unless url.kind_of?(String)
204
+
199
205
  local_path = download(url)
200
206
  @dangerfile.parse(Pathname.new(local_path))
201
207
  end
@@ -22,7 +22,7 @@ module Danger
22
22
  #
23
23
  # @example Warn when there are merge commits in the diff
24
24
  #
25
- # if git.commits.any? { |c| c.message =~ /^Merge branch 'master'/ }
25
+ # if git.commits.any? { |c| c.parents.count > 1 }
26
26
  # warn 'Please rebase to get rid of the merge commits in this PR'
27
27
  # end
28
28
  #
@@ -46,7 +46,7 @@ module Danger
46
46
 
47
47
  def initialize(dangerfile)
48
48
  super(dangerfile)
49
- raise unless dangerfile.env.scm.class == Danger::GitRepo
49
+ raise unless dangerfile.env.scm.class == Danger::GitRepo # rubocop:disable Style/ClassEqualityComparison
50
50
 
51
51
  @git = dangerfile.env.scm
52
52
  end
@@ -128,7 +128,7 @@ module Danger
128
128
  # @return [Git::Diff::DiffFile] from the gem `git`
129
129
  #
130
130
  def diff_for_file(file)
131
- (added_files + modified_files).include?(file) ? @git.diff[file] : nil
131
+ (added_files + modified_files + deleted_files).include?(file) ? @git.diff[file] : nil
132
132
  end
133
133
 
134
134
  # @!group Git Metadata
@@ -137,6 +137,7 @@ module Danger
137
137
  #
138
138
  def info_for_file(file)
139
139
  return nil unless modified_files.include?(file) || added_files.include?(file) || deleted_files.include?(file)
140
+
140
141
  stats = @git.diff.stats[:files][file]
141
142
  diff = @git.diff[file]
142
143
  {
@@ -76,6 +76,7 @@ module Danger
76
76
  # So that this init can fail.
77
77
  def self.new(dangerfile)
78
78
  return nil if dangerfile.env.request_source.class != Danger::RequestSources::GitHub
79
+
79
80
  super
80
81
  end
81
82
 
@@ -148,7 +149,7 @@ module Danger
148
149
  # @return [Boolean]
149
150
  #
150
151
  def pr_draft?
151
- pr_json["mergeable_state"] == "draft"
152
+ pr_json["draft"] == true
152
153
  end
153
154
 
154
155
  # @!group PR Commit Metadata
@@ -229,6 +230,7 @@ module Danger
229
230
  end
230
231
 
231
232
  return paths.first if paths.count < 2
233
+
232
234
  paths.first(paths.count - 1).join(", ") + " & " + paths.last
233
235
  end
234
236
 
@@ -65,7 +65,7 @@ module Danger
65
65
  # message "Reviewer roulete rolled for: #{reviewer.to_hash['name']} (@#{reviewer.to_hash['username']})"
66
66
  # gitlab.api.update_merge_request(project_id, mr_id, { assignee_id: reviewer.to_hash["id"] })
67
67
  # end
68
- #
68
+ #
69
69
  #
70
70
  # @see danger/danger
71
71
  # @tags core, gitlab
@@ -74,6 +74,7 @@ module Danger
74
74
  # So that this init can fail.
75
75
  def self.new(dangerfile)
76
76
  return nil if dangerfile.env.request_source.class != Danger::RequestSources::GitLab
77
+
77
78
  super
78
79
  end
79
80
 
@@ -240,6 +241,7 @@ module Danger
240
241
  end
241
242
 
242
243
  return paths.first if paths.count < 2
244
+
243
245
  paths.first(paths.count - 1).join(", ") + " & " + paths.last
244
246
  end
245
247
 
@@ -3,15 +3,15 @@ require "danger/plugin_support/plugin"
3
3
  # Danger
4
4
  module Danger
5
5
  # Handles interacting with local only plugin inside a Dangerfile.
6
- # It is support pluggin for dry_run command and does not expose any methods.
6
+ # It is support plugin for dry_run command and does not expose any methods.
7
7
  # But you can still use other plugins like git
8
8
  #
9
- # @example Check that added lines contains agreed form of words
9
+ # @example Check that added lines contains agreed form of words
10
10
  #
11
11
  # git.diff.each do |chunk|
12
12
  # chunk.patch.lines.grep(/^\+/).each do |added_line|
13
13
  # if added_line.gsub!(/(?<cancel>cancel)(?<rest>[^l[[:space:]][[:punct:]]]+)/i, '>>\k<cancel>-l-\k<rest><<')
14
- # fail "Single 'L' for cancellation-alike words in '#{added_line}'"
14
+ # fail "Single 'L' for cancellation-alike words in '#{added_line}'"
15
15
  # end
16
16
  # end
17
17
  # end
@@ -23,6 +23,7 @@ module Danger
23
23
  # So that this init can fail.
24
24
  def self.new(dangerfile)
25
25
  return nil if dangerfile.env.request_source.class != Danger::RequestSources::LocalOnly
26
+
26
27
  super
27
28
  end
28
29
 
@@ -149,6 +149,7 @@ module Danger
149
149
 
150
150
  warnings.flatten.each do |warning|
151
151
  next if should_ignore_violation(warning)
152
+
152
153
  @warnings << Violation.new(warning, sticky, file, line, type: :warning) if warning
153
154
  end
154
155
  end
@@ -174,11 +175,12 @@ module Danger
174
175
 
175
176
  failures.flatten.each do |failure|
176
177
  next if should_ignore_violation(failure)
178
+
177
179
  @errors << Violation.new(failure, sticky, file, line, type: :error) if failure
178
180
  end
179
181
  end
180
182
 
181
- alias_method :failure, :fail
183
+ alias failure fail
182
184
 
183
185
  # @!group Reporting
184
186
  # A list of all messages passed to Danger, including
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  require "danger/plugin_support/plugin"
4
2
 
5
3
  module Danger
@@ -58,6 +56,7 @@ module Danger
58
56
  # So that this init can fail.
59
57
  def self.new(dangerfile)
60
58
  return nil if dangerfile.env.request_source.class != Danger::RequestSources::VSTS
59
+
61
60
  super
62
61
  end
63
62
 
@@ -174,6 +173,7 @@ module Danger
174
173
  end
175
174
 
176
175
  return paths.first if paths.count < 2
176
+
177
177
  paths.first(paths.count - 1).join(", ") + " & " + paths.last
178
178
  end
179
179
 
@@ -184,7 +184,7 @@ module Danger
184
184
  end
185
185
 
186
186
  def branch_name(key)
187
- repo_matches = @source.pr_json[key].to_s.match(%r{refs\/heads\/(.*)})
187
+ repo_matches = @source.pr_json[key].to_s.match(%r{refs/heads/(.*)})
188
188
  repo_matches[1] unless repo_matches.nil?
189
189
  end
190
190
  end
@@ -37,9 +37,7 @@ module Danger
37
37
  # be raised.
38
38
  #
39
39
  def contents
40
- @contents ||= begin
41
- dsl_path && File.exist?(dsl_path) && File.read(dsl_path)
42
- end
40
+ @contents ||= dsl_path && File.exist?(dsl_path) && File.read(dsl_path)
43
41
  end
44
42
 
45
43
  # The message of the exception reports the content of podspec for the
@@ -104,6 +102,7 @@ module Danger
104
102
 
105
103
  trace_line = backtrace.find { |l| l.include?(dsl_path.to_s) } || trace_line
106
104
  return result unless trace_line
105
+
107
106
  line_numer = trace_line.split(":")[1].to_i - 1
108
107
  return result unless line_numer
109
108
 
@@ -19,8 +19,8 @@ module Danger
19
19
  respond_to_method(name, *args, &block)
20
20
  end
21
21
 
22
- def respond_to_missing?(name)
23
- __array__.respond_to?(name) || super
22
+ def respond_to_missing?(name, include_all)
23
+ __array__.respond_to?(name, include_all) || super
24
24
  end
25
25
 
26
26
  def to_a
@@ -11,7 +11,7 @@ module Danger
11
11
  include Danger::Helpers::CommentsParsingHelper
12
12
 
13
13
  def markdown_parser(text)
14
- Kramdown::Document.new(text, input: "GFM", smart_quotes: %w[apos apos quot quot])
14
+ Kramdown::Document.new(text, input: "GFM", smart_quotes: %w(apos apos quot quot))
15
15
  end
16
16
 
17
17
  # !@group Extension points
@@ -24,7 +24,9 @@ module Danger
24
24
  # @param [Bool] Should hide any generated link created
25
25
  #
26
26
  # @return [String] The Markdown compatible link
27
- def markdown_link_to_message(message, _)
27
+ def markdown_link_to_message(message, hide_link)
28
+ return "" if hide_link
29
+
28
30
  "#{message.file}#L#{message.line}"
29
31
  end
30
32
 
@@ -86,9 +88,9 @@ module Danger
86
88
  @tables = tables
87
89
  @markdowns = markdowns.map(&:message)
88
90
  @danger_id = danger_id
89
- @emoji_mapper = EmojiMapper.new(request_source.sub("_inline",""))
91
+ @emoji_mapper = EmojiMapper.new(request_source.sub("_inline", ""))
90
92
 
91
- return ERB.new(File.read(md_template), 0, "-").result(binding)
93
+ return ERB.new(File.read(md_template), trim_mode: "-").result(binding)
92
94
  end
93
95
 
94
96
  def generate_comment(warnings: [], errors: [], messages: [], markdowns: [], previous_violations: {}, danger_id: "danger", template: "github")
@@ -117,7 +119,6 @@ module Danger
117
119
  @resolved = resolved
118
120
  request_source_name = template.sub("_message_group", "")
119
121
 
120
-
121
122
  apply_template(danger_id: danger_id,
122
123
  markdowns: message_group.markdowns,
123
124
  template: template,
@@ -147,8 +148,8 @@ module Danger
147
148
 
148
149
  def generate_description(warnings: nil, errors: nil, template: "github")
149
150
  emoji_mapper = EmojiMapper.new(template)
150
- if errors.empty? && warnings.empty?
151
- return ENV['DANGER_SUCCESS_MESSAGE'] || "All green. #{random_compliment}"
151
+ if (errors.nil? || errors.empty?) && (warnings.nil? || warnings.empty?)
152
+ return ENV["DANGER_SUCCESS_MESSAGE"] || "All green. #{random_compliment}"
152
153
  else
153
154
  message = "#{emoji_mapper.map('warning')} "
154
155
  message += "#{'Error'.danger_pluralize(errors.count)}. " unless errors.empty?
@@ -29,6 +29,7 @@ module Danger
29
29
  tables.each do |table|
30
30
  match = danger_table?(table)
31
31
  next unless match
32
+
32
33
  title = match[1]
33
34
  kind = table_kind_from_title(title)
34
35
  next unless kind
@@ -51,8 +52,8 @@ module Danger
51
52
 
52
53
  private
53
54
 
54
- GITHUB_OLD_REGEX = %r{<th width="100%"(.*?)</th>}im
55
- NEW_REGEX = %r{<th.*data-danger-table="true"(.*?)</th>}im
55
+ GITHUB_OLD_REGEX = %r{<th width="100%"(.*?)</th>}im.freeze
56
+ NEW_REGEX = %r{<th.*data-danger-table="true"(.*?)</th>}im.freeze
56
57
 
57
58
  def danger_table?(table)
58
59
  # The old GitHub specific method relied on
@@ -18,7 +18,7 @@ module Danger
18
18
  TYPE_TO_EMOJI = {
19
19
  error: "no_entry_sign",
20
20
  warning: "warning",
21
- message: "book",
21
+ message: "book"
22
22
  }.freeze
23
23
 
24
24
  def initialize(template)
@@ -18,7 +18,6 @@ module Danger
18
18
  # Since we have a reference to the Dangerfile containing all the information
19
19
  # We need to redirect the self calls to the Dangerfile
20
20
 
21
- # rubocop:disable Style/MethodMissing
22
21
  def method_missing(method_sym, *arguments, **keyword_arguments, &block)
23
22
  if keyword_arguments.empty?
24
23
  @dangerfile.send(method_sym, *arguments, &block)
@@ -146,6 +146,7 @@ module Danger
146
146
  def apply_rules(json, type, rules)
147
147
  rules.each do |rule|
148
148
  next unless rule.function.call(json)
149
+
149
150
  rule.metadata = json
150
151
  rule.type = type
151
152
 
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  require "danger/helpers/comments_helper"
4
2
  require "danger/request_sources/bitbucket_cloud_api"
5
3
  require "danger/danger_core/message_group"
@@ -24,7 +22,6 @@ module Danger
24
22
 
25
23
  def initialize(ci_source, environment)
26
24
  self.ci_source = ci_source
27
- self.environment = environment
28
25
 
29
26
  @api = BitbucketCloudAPI.new(ci_source.repo_slug, ci_source.pull_request_id, nil, environment)
30
27
  end
@@ -105,7 +102,6 @@ module Danger
105
102
  template: "bitbucket_server")
106
103
  summary_body += "\n\n"
107
104
 
108
-
109
105
  # this isn't the most elegant thing in the world, but we need the group
110
106
  # with file: nil, line: nil so we can combine its info in with the
111
107
  # summary_body
@@ -146,8 +142,8 @@ module Danger
146
142
 
147
143
  if kind == :markdown
148
144
  body = generate_inline_markdown_body(message,
149
- danger_id: danger_id,
150
- template: "bitbucket_server")
145
+ danger_id: danger_id,
146
+ template: "bitbucket_server")
151
147
  else
152
148
  body = generate_inline_comment_body(emoji, message,
153
149
  danger_id: danger_id,
@@ -163,6 +159,7 @@ module Danger
163
159
  def delete_old_comments(danger_id: "danger")
164
160
  @api.fetch_comments.each do |c|
165
161
  next if c[:user][:uuid] != @api.my_uuid
162
+
166
163
  @api.delete_comment(c[:id]) if c[:content][:raw] =~ /generated_by_#{danger_id}/
167
164
  end
168
165
  end