danger 8.5.0 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/danger/ci_source/code_build.rb +19 -5
- data/lib/danger/commands/pr.rb +2 -1
- data/lib/danger/danger_core/dangerfile.rb +2 -2
- data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +1 -1
- data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +1 -1
- data/lib/danger/request_sources/bitbucket_server.rb +48 -8
- data/lib/danger/request_sources/bitbucket_server_api.rb +5 -0
- data/lib/danger/request_sources/vsts.rb +1 -1
- data/lib/danger/scm_source/git_repo.rb +2 -1
- data/lib/danger/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 613bfd46794c42423189f27277eb745250ebae6a3bed733c9ba499d7507c1671
|
4
|
+
data.tar.gz: 309007d0119085c78e8a18dec65d5fe8f2c46d67a9267b8e7ddd7fe8f284e31a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
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}"
|
data/lib/danger/commands/pr.rb
CHANGED
@@ -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,7 +289,7 @@ 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)
|
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
|
@@ -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
|
|
@@ -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
|
@@ -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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
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
|
@@ -55,7 +55,8 @@ module Danger
|
|
55
55
|
def exec(string)
|
56
56
|
require "open3"
|
57
57
|
Dir.chdir(self.folder || ".") do
|
58
|
-
|
58
|
+
git_command = string.split(" ").dup.unshift("git")
|
59
|
+
Open3.popen2(default_env, *git_command) do |_stdin, stdout, _wait_thr|
|
59
60
|
stdout.read.rstrip
|
60
61
|
end
|
61
62
|
end
|
data/lib/danger/version.rb
CHANGED
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:
|
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-
|
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: '
|
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: '
|
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.
|
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.
|
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: []
|