danger 8.4.5 → 9.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/bin/danger +1 -1
- data/lib/danger/ci_source/appcircle.rb +83 -0
- data/lib/danger/ci_source/appveyor.rb +1 -0
- data/lib/danger/ci_source/azure_pipelines.rb +20 -5
- data/lib/danger/ci_source/bamboo.rb +1 -1
- data/lib/danger/ci_source/bitbucket_pipelines.rb +1 -2
- data/lib/danger/ci_source/bitrise.rb +10 -10
- data/lib/danger/ci_source/buildkite.rb +1 -1
- data/lib/danger/ci_source/circle.rb +1 -1
- data/lib/danger/ci_source/circle_api.rb +2 -2
- data/lib/danger/ci_source/code_build.rb +20 -6
- data/lib/danger/ci_source/codefresh.rb +1 -1
- data/lib/danger/ci_source/concourse.rb +4 -5
- data/lib/danger/ci_source/custom_ci_with_github.rb +45 -0
- data/lib/danger/ci_source/dotci.rb +4 -6
- data/lib/danger/ci_source/github_actions.rb +6 -6
- data/lib/danger/ci_source/gitlab_ci.rb +4 -4
- data/lib/danger/ci_source/jenkins.rb +22 -23
- data/lib/danger/ci_source/local_git_repo.rb +7 -1
- data/lib/danger/ci_source/local_only_git_repo.rb +1 -0
- data/lib/danger/ci_source/support/find_repo_info_from_url.rb +11 -10
- data/lib/danger/ci_source/support/pull_request_finder.rb +15 -7
- data/lib/danger/ci_source/teamcity.rb +1 -1
- data/lib/danger/ci_source/xcode_cloud.rb +7 -7
- data/lib/danger/commands/init.rb +1 -1
- data/lib/danger/commands/local.rb +3 -3
- data/lib/danger/commands/local_helpers/http_cache.rb +2 -0
- data/lib/danger/commands/local_helpers/local_setup.rb +2 -0
- data/lib/danger/commands/local_helpers/pry_setup.rb +1 -0
- data/lib/danger/commands/plugins/plugin_json.rb +1 -3
- data/lib/danger/commands/plugins/plugin_lint.rb +0 -2
- data/lib/danger/commands/plugins/plugin_readme.rb +2 -5
- data/lib/danger/commands/pr.rb +2 -1
- data/lib/danger/commands/runner.rb +1 -1
- data/lib/danger/commands/staging.rb +7 -7
- data/lib/danger/commands/systems.rb +4 -6
- data/lib/danger/comment_generators/gitlab_inline.md.erb +1 -1
- data/lib/danger/comment_generators/vsts_inline.md.erb +17 -0
- data/lib/danger/core_ext/file_list.rb +2 -2
- data/lib/danger/danger_core/dangerfile.rb +16 -16
- data/lib/danger/danger_core/environment_manager.rb +2 -1
- data/lib/danger/danger_core/executor.rb +10 -11
- data/lib/danger/danger_core/message_aggregator.rb +1 -0
- data/lib/danger/danger_core/messages/base.rb +1 -0
- data/lib/danger/danger_core/messages/markdown.rb +3 -4
- data/lib/danger/danger_core/messages/violation.rb +1 -2
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +1 -3
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +4 -4
- data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +9 -3
- data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +4 -3
- data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +2 -0
- data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +3 -1
- data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +4 -3
- data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +3 -1
- data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +3 -3
- data/lib/danger/danger_core/standard_error.rb +2 -3
- data/lib/danger/helpers/comments_helper.rb +8 -7
- data/lib/danger/helpers/comments_parsing_helper.rb +3 -2
- data/lib/danger/helpers/emoji_mapper.rb +1 -1
- data/lib/danger/plugin_support/plugin.rb +0 -1
- data/lib/danger/plugin_support/plugin_linter.rb +1 -0
- data/lib/danger/request_sources/bitbucket_cloud.rb +17 -14
- data/lib/danger/request_sources/bitbucket_cloud_api.rb +2 -4
- data/lib/danger/request_sources/bitbucket_server.rb +47 -10
- data/lib/danger/request_sources/bitbucket_server_api.rb +14 -10
- data/lib/danger/request_sources/code_insights_api.rb +7 -11
- data/lib/danger/request_sources/github/github.rb +15 -14
- data/lib/danger/request_sources/github/github_review.rb +3 -2
- data/lib/danger/request_sources/github/github_review_resolver.rb +0 -2
- data/lib/danger/request_sources/github/github_review_unsupported.rb +0 -2
- data/lib/danger/request_sources/gitlab.rb +46 -58
- data/lib/danger/request_sources/local_only.rb +0 -2
- data/lib/danger/request_sources/request_source.rb +4 -4
- data/lib/danger/request_sources/support/get_ignored_violation.rb +1 -1
- data/lib/danger/request_sources/vsts.rb +175 -14
- data/lib/danger/request_sources/vsts_api.rb +39 -4
- data/lib/danger/scm_source/git_repo.rb +2 -1
- data/lib/danger/version.rb +1 -1
- data/lib/danger.rb +1 -0
- metadata +42 -40
- data/lib/danger/ci_source/vsts.rb +0 -73
@@ -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
|
-
|
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.
|
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
|
|
@@ -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
|
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
|
-
|
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
|
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 ||=
|
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
|
|
@@ -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
|
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),
|
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[
|
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,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)
|
@@ -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"
|
@@ -80,15 +78,20 @@ module Danger
|
|
80
78
|
messages = update_inline_comments_for_kind!(:messages, messages, danger_id: danger_id)
|
81
79
|
markdowns = update_inline_comments_for_kind!(:markdowns, markdowns, danger_id: danger_id)
|
82
80
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
81
|
+
has_comments = (warnings.count > 0 || errors.count > 0 || messages.count > 0 || markdowns.count > 0)
|
82
|
+
if has_comments
|
83
|
+
comment = generate_description(warnings: warnings,
|
84
|
+
errors: errors)
|
85
|
+
comment += "\n\n"
|
86
|
+
comment += generate_comment(warnings: warnings,
|
87
|
+
errors: errors,
|
88
|
+
messages: messages,
|
89
|
+
markdowns: markdowns,
|
90
|
+
previous_violations: {},
|
91
|
+
danger_id: danger_id,
|
92
|
+
template: "bitbucket_server")
|
93
|
+
@api.post_comment(comment)
|
94
|
+
end
|
92
95
|
end
|
93
96
|
|
94
97
|
def update_pr_by_line!(message_groups:,
|
@@ -104,7 +107,6 @@ module Danger
|
|
104
107
|
template: "bitbucket_server")
|
105
108
|
summary_body += "\n\n"
|
106
109
|
|
107
|
-
|
108
110
|
# this isn't the most elegant thing in the world, but we need the group
|
109
111
|
# with file: nil, line: nil so we can combine its info in with the
|
110
112
|
# summary_body
|
@@ -145,8 +147,8 @@ module Danger
|
|
145
147
|
|
146
148
|
if kind == :markdown
|
147
149
|
body = generate_inline_markdown_body(message,
|
148
|
-
|
149
|
-
|
150
|
+
danger_id: danger_id,
|
151
|
+
template: "bitbucket_server")
|
150
152
|
else
|
151
153
|
body = generate_inline_comment_body(emoji, message,
|
152
154
|
danger_id: danger_id,
|
@@ -162,6 +164,7 @@ module Danger
|
|
162
164
|
def delete_old_comments(danger_id: "danger")
|
163
165
|
@api.fetch_comments.each do |c|
|
164
166
|
next if c[:user][:uuid] != @api.my_uuid
|
167
|
+
|
165
168
|
@api.delete_comment(c[:id]) if c[:content][:raw] =~ /generated_by_#{danger_id}/
|
166
169
|
end
|
167
170
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# coding: utf-8
|
3
2
|
|
4
3
|
require "danger/helpers/comments_helper"
|
5
4
|
|
@@ -57,7 +56,7 @@ module Danger
|
|
57
56
|
def fetch_comments
|
58
57
|
values = []
|
59
58
|
# TODO: use a url parts encoder to encode the query
|
60
|
-
corrected_uuid = @my_uuid[1...-1]
|
59
|
+
corrected_uuid = @my_uuid[1...-1] unless @my_uuid.nil? # Endpoint doesnt support curly brackets for this, so remove them for this
|
61
60
|
uri = "#{pr_api_endpoint}/comments?pagelen=100&q=deleted+%7E+false+AND+user.uuid+%7E+%22#{corrected_uuid}%22"
|
62
61
|
|
63
62
|
while uri
|
@@ -114,7 +113,7 @@ module Danger
|
|
114
113
|
uri = URI.parse("https://bitbucket.org/site/oauth2/access_token")
|
115
114
|
req = Net::HTTP::Post.new(uri.request_uri, { "Content-Type" => "application/json" })
|
116
115
|
req.basic_auth oauth_key, oauth_secret
|
117
|
-
req.set_form_data({
|
116
|
+
req.set_form_data({ "grant_type" => "client_credentials" })
|
118
117
|
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
119
118
|
http.request(req)
|
120
119
|
end
|
@@ -177,7 +176,6 @@ module Danger
|
|
177
176
|
def error_fetching_json(url, status_code)
|
178
177
|
"Error fetching json for: #{url}, status code: #{status_code}"
|
179
178
|
end
|
180
|
-
|
181
179
|
end
|
182
180
|
end
|
183
181
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require "danger/helpers/comments_helper"
|
4
2
|
require "danger/request_sources/bitbucket_server_api"
|
5
3
|
require "danger/request_sources/code_insights_api"
|
@@ -9,7 +7,7 @@ module Danger
|
|
9
7
|
module RequestSources
|
10
8
|
class BitbucketServer < RequestSource
|
11
9
|
include Danger::Helpers::CommentsHelper
|
12
|
-
attr_accessor :pr_json
|
10
|
+
attr_accessor :pr_json, :dismiss_out_of_range_messages
|
13
11
|
|
14
12
|
def self.env_vars
|
15
13
|
[
|
@@ -25,12 +23,14 @@ module Danger
|
|
25
23
|
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_TITLE",
|
26
24
|
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_DESCRIPTION",
|
27
25
|
"DANGER_BITBUCKETSERVER_CODE_INSIGHTS_REPORT_LOGO_URL",
|
28
|
-
"DANGER_BITBUCKETSERVER_VERIFY_SSL"
|
26
|
+
"DANGER_BITBUCKETSERVER_VERIFY_SSL",
|
27
|
+
"DANGER_BITBUCKETSERVER_DISMISS_OUT_OF_RANGE_MESSAGES"
|
29
28
|
]
|
30
29
|
end
|
31
30
|
|
32
31
|
def initialize(ci_source, environment)
|
33
32
|
self.ci_source = ci_source
|
33
|
+
self.dismiss_out_of_range_messages = environment["DANGER_BITBUCKETSERVER_DISMISS_OUT_OF_RANGE_MESSAGES"] == "true"
|
34
34
|
|
35
35
|
project, slug = ci_source.repo_slug.split("/")
|
36
36
|
@api = BitbucketServerAPI.new(project, slug, ci_source.pull_request_id, environment)
|
@@ -58,6 +58,10 @@ module Danger
|
|
58
58
|
self.pr_json = @api.fetch_pr_json
|
59
59
|
end
|
60
60
|
|
61
|
+
def pr_diff
|
62
|
+
@pr_diff ||= @api.fetch_pr_diff
|
63
|
+
end
|
64
|
+
|
61
65
|
def setup_danger_branches
|
62
66
|
base_branch = self.pr_json[:toRef][:id].sub("refs/heads/", "")
|
63
67
|
base_commit = self.pr_json[:toRef][:latestCommit]
|
@@ -134,12 +138,22 @@ module Danger
|
|
134
138
|
end
|
135
139
|
|
136
140
|
def main_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
141
|
+
if dismiss_out_of_range_messages
|
142
|
+
{
|
143
|
+
warnings: warnings.reject(&:inline?),
|
144
|
+
errors: errors.reject(&:inline?),
|
145
|
+
messages: messages.reject(&:inline?),
|
146
|
+
markdowns: markdowns.reject(&:inline?)
|
147
|
+
}
|
148
|
+
else
|
149
|
+
in_diff = proc { |a| find_position_in_diff?(a.file, a.line) }
|
150
|
+
{
|
151
|
+
warnings: warnings.reject(&in_diff),
|
152
|
+
errors: errors.reject(&in_diff),
|
153
|
+
messages: messages.reject(&in_diff),
|
154
|
+
markdowns: markdowns.reject(&in_diff)
|
155
|
+
}
|
156
|
+
end
|
143
157
|
end
|
144
158
|
|
145
159
|
def inline_violations_group(warnings: [], errors: [], messages: [], markdowns: [])
|
@@ -148,6 +162,7 @@ module Danger
|
|
148
162
|
next 1 unless b.file && b.line
|
149
163
|
|
150
164
|
next a.line <=> b.line if a.file == b.file
|
165
|
+
|
151
166
|
next a.file <=> b.file
|
152
167
|
end
|
153
168
|
|
@@ -168,6 +183,28 @@ module Danger
|
|
168
183
|
puts self.pr_json.to_json
|
169
184
|
@api.update_pr_build_status(status, changeset, build_job_link, description)
|
170
185
|
end
|
186
|
+
|
187
|
+
def find_position_in_diff?(file, line)
|
188
|
+
return nil if file.nil? || line.nil?
|
189
|
+
return nil if file.empty?
|
190
|
+
|
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] ||= file_diff(file)[:hunks].map do |hunk|
|
201
|
+
hunk[:segments].select { |segment| segment[:type] == "ADDED" }.map do |segment|
|
202
|
+
segment[:lines].map do |line|
|
203
|
+
line[:destination]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end.flatten
|
207
|
+
end
|
171
208
|
end
|
172
209
|
end
|
173
210
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# coding: utf-8
|
3
2
|
|
4
3
|
require "openssl"
|
5
4
|
require "danger/helpers/comments_helper"
|
@@ -43,6 +42,11 @@ module Danger
|
|
43
42
|
fetch_json(uri)
|
44
43
|
end
|
45
44
|
|
45
|
+
def fetch_pr_diff
|
46
|
+
uri = URI("#{pr_api_endpoint}/diff?withComments=false")
|
47
|
+
fetch_json(uri)
|
48
|
+
end
|
49
|
+
|
46
50
|
def fetch_last_comments
|
47
51
|
uri = URI("#{pr_api_endpoint}/activities?limit=1000")
|
48
52
|
fetch_json(uri)[:values].select { |v| v[:action] == "COMMENTED" }.map { |v| v[:comment] }
|
@@ -60,9 +64,9 @@ module Danger
|
|
60
64
|
end
|
61
65
|
|
62
66
|
def update_pr_build_status(status, changeset, build_job_link, description)
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
uri = URI("#{self.host}/rest/build-status/1.0/commits/#{changeset}")
|
68
|
+
body = build_status_body(status, build_job_link, description)
|
69
|
+
post(uri, body)
|
66
70
|
end
|
67
71
|
|
68
72
|
private
|
@@ -113,12 +117,12 @@ module Danger
|
|
113
117
|
end
|
114
118
|
|
115
119
|
def build_status_body(status, build_job_link, description)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
120
|
+
body = {}
|
121
|
+
body["state"] = status
|
122
|
+
body["key"] = self.key
|
123
|
+
body["url"] = build_job_link
|
124
|
+
body["description"] = description if description
|
125
|
+
return body.to_json
|
122
126
|
end
|
123
127
|
end
|
124
128
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# coding: utf-8
|
3
2
|
|
4
3
|
module Danger
|
5
4
|
module RequestSources
|
@@ -38,7 +37,7 @@ module Danger
|
|
38
37
|
|
39
38
|
def delete_report(commit)
|
40
39
|
uri = URI(report_endpoint_at_commit(commit))
|
41
|
-
request = Net::HTTP::Delete.new(uri.request_uri, {"Content-Type" => "application/json"})
|
40
|
+
request = Net::HTTP::Delete.new(uri.request_uri, { "Content-Type" => "application/json" })
|
42
41
|
request.basic_auth @username, @password
|
43
42
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
|
44
43
|
http.request(request)
|
@@ -50,7 +49,6 @@ module Danger
|
|
50
49
|
# HTTP 4xx - 5xx
|
51
50
|
abort "\nError deleting report from Code Insights API: #{response.code} (#{response.message}) - #{response.body}\n\n"
|
52
51
|
end
|
53
|
-
|
54
52
|
end
|
55
53
|
|
56
54
|
def send_report(commit, inline_warnings, inline_errors, inline_messages)
|
@@ -64,15 +62,14 @@ module Danger
|
|
64
62
|
|
65
63
|
def put_report(commit, inline_errors_count)
|
66
64
|
uri = URI(report_endpoint_at_commit(commit))
|
67
|
-
request = Net::HTTP::Put.new(uri.request_uri, {"Content-Type" => "application/json"})
|
65
|
+
request = Net::HTTP::Put.new(uri.request_uri, { "Content-Type" => "application/json" })
|
68
66
|
request.basic_auth @username, @password
|
69
|
-
request.body = {"title": @report_title,
|
67
|
+
request.body = { "title": @report_title,
|
70
68
|
"details": @report_description,
|
71
|
-
"result":
|
69
|
+
"result": inline_errors_count > 0 ? "FAIL" : "PASS",
|
72
70
|
"reporter": @username,
|
73
71
|
"link": "https://github.com/danger/danger",
|
74
|
-
"logoURL": @logo_url
|
75
|
-
}.to_json
|
72
|
+
"logoURL": @logo_url }.to_json
|
76
73
|
|
77
74
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl) do |http|
|
78
75
|
http.request(request)
|
@@ -103,8 +100,8 @@ module Danger
|
|
103
100
|
annotations << violation_hash_with_severity(violation, "HIGH")
|
104
101
|
end
|
105
102
|
|
106
|
-
body = {annotations: annotations}.to_json
|
107
|
-
request = Net::HTTP::Post.new(uri.request_uri, {"Content-Type" => "application/json"})
|
103
|
+
body = { annotations: annotations }.to_json
|
104
|
+
request = Net::HTTP::Post.new(uri.request_uri, { "Content-Type" => "application/json" })
|
108
105
|
request.basic_auth @username, @password
|
109
106
|
request.body = body
|
110
107
|
|
@@ -140,7 +137,6 @@ module Danger
|
|
140
137
|
def use_ssl
|
141
138
|
@host.include? "https://"
|
142
139
|
end
|
143
|
-
|
144
140
|
end
|
145
141
|
end
|
146
142
|
end
|