danger 8.6.1 → 9.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: 691f7a26ea0a29f107e6f848bdf7450d2043dc15f5c385c136c1a9d818120c3f
4
- data.tar.gz: d5f84a85ec8419dbbfbdcb742ffb15b5fe075d3bf1f676859152a0bb7b466633
3
+ metadata.gz: 613bfd46794c42423189f27277eb745250ebae6a3bed733c9ba499d7507c1671
4
+ data.tar.gz: 309007d0119085c78e8a18dec65d5fe8f2c46d67a9267b8e7ddd7fe8f284e31a
5
5
  SHA512:
6
- metadata.gz: b712f8566113397b952ebd93e33d1d42b38d1b1a9d04e678971c35feb46a5bfb057236b0ccffc250560df6b1da001fe31f848024de318850c93ecb6af6eb0994
7
- data.tar.gz: c89ab31d3afe5d668046629643d65858d6eeeea3d5f67006170af38e9a8c31673789de472501d37ff923c41fb538193cce767ae9567ef4a9a474aca96cf4aad4
6
+ metadata.gz: d934930d7677f61ec2c549c2418396f6bbb8c625fd1bc03f51952d9b5a6c4384b0e6a72fa496a0296bc1c6a524dbef8712f0bf73bbc25ff11897889896b928e4
7
+ data.tar.gz: c6d450cf48ed09ca021849ff8166e102bc85ab970cefa3a715f5047e807b9f6dc8b2eaa3aa59b0e965e31efbde97b70d3b5efcc9cf5ddb50b51789b1385de25f
@@ -5,6 +5,7 @@ module Danger
5
5
  # ### CI Setup
6
6
  #
7
7
  # In CodeBuild, make sure to correctly forward CODEBUILD_BUILD_ID, CODEBUILD_SOURCE_VERSION, CODEBUILD_SOURCE_REPO_URL and DANGER_GITHUB_API_TOKEN.
8
+ # In CodeBuild with batch builds, make sure to correctly forward CODEBUILD_BUILD_ID, CODEBUILD_WEBHOOK_TRIGGER, CODEBUILD_SOURCE_REPO_URL, CODEBUILD_BATCH_BUILD_IDENTIFIER and DANGER_GITHUB_API_TOKEN.
8
9
  #
9
10
  # ### Token Setup
10
11
  #
@@ -25,7 +26,11 @@ module Danger
25
26
 
26
27
  def initialize(env)
27
28
  self.repo_slug = self.class.extract_repo_slug(env)
28
- self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1].to_i
29
+ if env["CODEBUILD_BATCH_BUILD_IDENTIFIER"]
30
+ self.pull_request_id = env["CODEBUILD_WEBHOOK_TRIGGER"].split("/")[1].to_i
31
+ else
32
+ self.pull_request_id = env["CODEBUILD_SOURCE_VERSION"].split("/")[1].to_i
33
+ end
29
34
  self.repo_url = self.class.extract_repo_url(env)
30
35
  end
31
36
 
@@ -44,11 +49,20 @@ module Danger
44
49
  end
45
50
 
46
51
  def self.extract_pr_url(env)
47
- return nil unless env.key? "CODEBUILD_SOURCE_VERSION"
48
- return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
49
- return nil unless env["CODEBUILD_SOURCE_VERSION"].split("/").length == 2
52
+ if env["CODEBUILD_BATCH_BUILD_IDENTIFIER"]
53
+ return nil unless env.key? "CODEBUILD_WEBHOOK_TRIGGER"
54
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
55
+ return nil unless env["CODEBUILD_WEBHOOK_TRIGGER"].split("/").length == 2
56
+
57
+ event_type, pr_number = env["CODEBUILD_WEBHOOK_TRIGGER"].split("/")
58
+ return nil unless event_type == "pr"
59
+ else
60
+ return nil unless env.key? "CODEBUILD_SOURCE_VERSION"
61
+ return nil unless env.key? "CODEBUILD_SOURCE_REPO_URL"
62
+ return nil unless env["CODEBUILD_SOURCE_VERSION"].split("/").length == 2
50
63
 
51
- _source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
64
+ _source_origin, pr_number = env["CODEBUILD_SOURCE_VERSION"].split("/")
65
+ end
52
66
  github_repo_url = env["CODEBUILD_SOURCE_REPO_URL"].gsub(/\.git$/, "")
53
67
 
54
68
  "#{github_repo_url}/pull/#{pr_number}"
@@ -132,7 +132,7 @@ module Danger
132
132
  #
133
133
  def import_dangerfile_from_path(path)
134
134
  raise "`import_dangerfile_from_path` requires a string" unless path.kind_of?(String)
135
- local_path = File.join(path, "Dangerfile")
135
+ local_path = File.file?(path) ? path : File.join(path, "Dangerfile")
136
136
  @dangerfile.parse(Pathname.new(local_path))
137
137
  end
138
138
 
@@ -9,7 +9,7 @@ module Danger
9
9
  module RequestSources
10
10
  class BitbucketServer < RequestSource
11
11
  include Danger::Helpers::CommentsHelper
12
- attr_accessor :pr_json
12
+ attr_accessor :pr_json, :dismiss_out_of_range_messages
13
13
 
14
14
  def self.env_vars
15
15
  [
@@ -25,12 +25,14 @@ module Danger
25
25
  "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_TITLE",
26
26
  "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_DESCRIPTION",
27
27
  "DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_LOGO_URL",
28
- "DANGER_BITBUCKETSERVER_VERIFY_SSL"
28
+ "DANGER_BITBUCKETSERVER_VERIFY_SSL",
29
+ "DANGER_BITBUCKETSERVER_DISMISS_OUT_OF_RANGE_MESSAGES"
29
30
  ]
30
31
  end
31
32
 
32
33
  def initialize(ci_source, environment)
33
34
  self.ci_source = ci_source
35
+ self.dismiss_out_of_range_messages = environment["DANGER_BITBUCKETSERVER_DISMISS_OUT_OF_RANGE_MESSAGES"] == 'true'
34
36
 
35
37
  project, slug = ci_source.repo_slug.split("/")
36
38
  @api = BitbucketServerAPI.new(project, slug, ci_source.pull_request_id, environment)
@@ -58,6 +60,10 @@ module Danger
58
60
  self.pr_json = @api.fetch_pr_json
59
61
  end
60
62
 
63
+ def pr_diff
64
+ @pr_diff ||= @api.fetch_pr_diff
65
+ end
66
+
61
67
  def setup_danger_branches
62
68
  base_branch = self.pr_json[:toRef][:id].sub("refs/heads/", "")
63
69
  base_commit = self.pr_json[:toRef][:latestCommit]
@@ -134,12 +140,22 @@ module Danger
134
140
  end
135
141
 
136
142
  def main_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
137
- {
138
- warnings: warnings.reject(&:inline?),
139
- errors: errors.reject(&:inline?),
140
- messages: messages.reject(&:inline?),
141
- markdowns: markdowns.reject(&:inline?)
142
- }
143
+ if dismiss_out_of_range_messages
144
+ {
145
+ warnings: warnings.reject(&:inline?),
146
+ errors: errors.reject(&:inline?),
147
+ messages: messages.reject(&:inline?),
148
+ markdowns: markdowns.reject(&:inline?)
149
+ }
150
+ else
151
+ in_diff = proc { |a| find_position_in_diff?(a.file, a.line) }
152
+ {
153
+ warnings: warnings.reject(&in_diff),
154
+ errors: errors.reject(&in_diff),
155
+ messages: messages.reject(&in_diff),
156
+ markdowns: markdowns.reject(&in_diff)
157
+ }
158
+ end
143
159
  end
144
160
 
145
161
  def inline_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
@@ -168,6 +184,30 @@ module Danger
168
184
  puts self.pr_json.to_json
169
185
  @api.update_pr_build_status(status, changeset, build_job_link, description)
170
186
  end
187
+
188
+ def find_position_in_diff?(file, line)
189
+ return nil if file.nil? || line.nil?
190
+ return nil if file.empty?
191
+ added_lines(file).include?(line)
192
+ end
193
+
194
+ def file_diff(file)
195
+ self.pr_diff[:diffs].find{|diff| diff[:destination] && diff[:destination][:toString] == file } || {:hunks => []}
196
+ end
197
+
198
+ def added_lines(file)
199
+ @added_lines ||= {}
200
+ @added_lines[file] ||= begin
201
+ file_diff(file)[:hunks].map do |hunk|
202
+ hunk[:segments].select{|segment| segment[:type] == 'ADDED' }.map do |segment|
203
+ segment[:lines].map do |line|
204
+ line[:destination]
205
+ end
206
+ end
207
+ end.flatten
208
+ end
209
+ end
210
+
171
211
  end
172
212
  end
173
213
  end
@@ -43,6 +43,11 @@ module Danger
43
43
  fetch_json(uri)
44
44
  end
45
45
 
46
+ def fetch_pr_diff
47
+ uri = URI("#{pr_api_endpoint}/diff?withComments=false")
48
+ fetch_json(uri)
49
+ end
50
+
46
51
  def fetch_last_comments
47
52
  uri = URI("#{pr_api_endpoint}/activities?limit=1000")
48
53
  fetch_json(uri)[:values].select { |v| v[:action] == "COMMENTED" }.map { |v| v[:comment] }
@@ -195,7 +195,7 @@ module Danger
195
195
  body = generate_inline_markdown_body(m, danger_id: danger_id, template: "vsts")
196
196
  else
197
197
  # Hide the inline link behind a span
198
- m.message.gsub!("\n", "<br />")
198
+ m.message = m.message.gsub("\n", "<br />")
199
199
  m = process_markdown(m, true)
200
200
  body = generate_inline_comment_body(emoji, m, danger_id: danger_id, template: "vsts")
201
201
  # A comment might be in previous_violations because only now it's part of the unified diff
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "8.6.1".freeze
2
+ VERSION = "9.0.0".freeze
3
3
  DESCRIPTION = "Like Unit Tests, but for your Team Culture.".freeze
4
4
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.6.1
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orta Therox
8
8
  - Juanito Fatas
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-04-22 00:00:00.000000000 Z
12
+ date: 2022-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -135,14 +135,14 @@ dependencies:
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '4.7'
138
+ version: '5.0'
139
139
  type: :runtime
140
140
  prerelease: false
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '4.7'
145
+ version: '5.0'
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: terminal-table
148
148
  requirement: !ruby/object:Gem::Requirement
@@ -328,7 +328,7 @@ homepage: https://github.com/danger/danger
328
328
  licenses:
329
329
  - MIT
330
330
  metadata: {}
331
- post_install_message:
331
+ post_install_message:
332
332
  rdoc_options: []
333
333
  require_paths:
334
334
  - lib
@@ -336,15 +336,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
336
336
  requirements:
337
337
  - - ">="
338
338
  - !ruby/object:Gem::Version
339
- version: 2.4.0
339
+ version: 2.7.0
340
340
  required_rubygems_version: !ruby/object:Gem::Requirement
341
341
  requirements:
342
342
  - - ">="
343
343
  - !ruby/object:Gem::Version
344
344
  version: '0'
345
345
  requirements: []
346
- rubygems_version: 3.1.4
347
- signing_key:
346
+ rubygems_version: 3.1.6
347
+ signing_key:
348
348
  specification_version: 4
349
349
  summary: Like Unit Tests, but for your Team Culture.
350
350
  test_files: []