danger 9.5.3 → 9.6.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 +4 -4
- data/bin/danger +2 -0
- data/lib/danger/ci_source/appcenter.rb +2 -0
- data/lib/danger/ci_source/appcircle.rb +2 -0
- data/lib/danger/ci_source/appveyor.rb +2 -0
- data/lib/danger/ci_source/azure_pipelines.rb +2 -0
- data/lib/danger/ci_source/bamboo.rb +2 -0
- data/lib/danger/ci_source/bitbucket_pipelines.rb +2 -0
- data/lib/danger/ci_source/bitrise.rb +2 -1
- data/lib/danger/ci_source/buddybuild.rb +2 -0
- data/lib/danger/ci_source/buildkite.rb +2 -0
- data/lib/danger/ci_source/ci_source.rb +2 -0
- data/lib/danger/ci_source/circle.rb +3 -1
- data/lib/danger/ci_source/circle_api.rb +5 -3
- data/lib/danger/ci_source/cirrus.rb +2 -0
- data/lib/danger/ci_source/code_build.rb +2 -0
- data/lib/danger/ci_source/codefresh.rb +3 -1
- data/lib/danger/ci_source/codemagic.rb +2 -0
- data/lib/danger/ci_source/codeship.rb +2 -0
- data/lib/danger/ci_source/concourse.rb +2 -0
- data/lib/danger/ci_source/dotci.rb +2 -0
- data/lib/danger/ci_source/drone.rb +2 -0
- data/lib/danger/ci_source/github_actions.rb +2 -0
- data/lib/danger/ci_source/gitlab_ci.rb +2 -0
- data/lib/danger/ci_source/jenkins.rb +2 -0
- data/lib/danger/ci_source/local_git_repo.rb +9 -5
- data/lib/danger/ci_source/screwdriver.rb +2 -0
- data/lib/danger/ci_source/semaphore.rb +2 -0
- data/lib/danger/ci_source/support/commits.rb +3 -1
- data/lib/danger/ci_source/support/find_repo_info_from_logs.rb +3 -1
- data/lib/danger/ci_source/support/find_repo_info_from_url.rb +5 -1
- data/lib/danger/ci_source/support/local_pull_request.rb +3 -1
- data/lib/danger/ci_source/support/no_pull_request.rb +2 -0
- data/lib/danger/ci_source/support/no_repo_info.rb +2 -0
- data/lib/danger/ci_source/support/pull_request_finder.rb +67 -28
- data/lib/danger/ci_source/support/remote_pull_request.rb +2 -0
- data/lib/danger/ci_source/support/repo_info.rb +2 -0
- data/lib/danger/ci_source/surf.rb +2 -0
- data/lib/danger/ci_source/teamcity.rb +14 -1
- data/lib/danger/ci_source/travis.rb +2 -0
- data/lib/danger/ci_source/xcode_cloud.rb +2 -0
- data/lib/danger/ci_source/xcode_server.rb +2 -0
- data/lib/danger/clients/rubygems_client.rb +4 -2
- data/lib/danger/commands/dangerfile/gem.rb +3 -1
- data/lib/danger/commands/dangerfile/init.rb +3 -1
- data/lib/danger/commands/dry_run.rb +2 -0
- data/lib/danger/commands/init.rb +22 -20
- data/lib/danger/commands/init_helpers/interviewer.rb +6 -4
- data/lib/danger/commands/local.rb +2 -0
- data/lib/danger/commands/local_helpers/http_cache.rb +2 -0
- data/lib/danger/commands/local_helpers/local_setup.rb +4 -5
- data/lib/danger/commands/local_helpers/pry_setup.rb +3 -1
- data/lib/danger/commands/mr.rb +91 -0
- data/lib/danger/commands/plugins/plugin_json.rb +2 -0
- data/lib/danger/commands/plugins/plugin_lint.rb +2 -0
- data/lib/danger/commands/plugins/plugin_readme.rb +2 -0
- data/lib/danger/commands/pr.rb +4 -2
- data/lib/danger/commands/runner.rb +3 -0
- data/lib/danger/commands/staging.rb +2 -0
- data/lib/danger/commands/systems.rb +3 -1
- data/lib/danger/core_ext/file_list.rb +2 -0
- data/lib/danger/core_ext/string.rb +6 -4
- data/lib/danger/danger_core/dangerfile.rb +7 -4
- data/lib/danger/danger_core/dangerfile_dsl.rb +2 -0
- data/lib/danger/danger_core/dangerfile_generator.rb +2 -0
- data/lib/danger/danger_core/environment_manager.rb +13 -10
- data/lib/danger/danger_core/executor.rb +3 -1
- data/lib/danger/danger_core/messages/base.rb +7 -2
- data/lib/danger/danger_core/messages/markdown.rb +36 -6
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb +2 -0
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +4 -2
- data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +2 -0
- data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +2 -0
- data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +3 -1
- data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +3 -1
- data/lib/danger/danger_core/plugins/dangerfile_local_only_plugin.rb +2 -0
- data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +19 -1
- data/lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb +4 -2
- data/lib/danger/danger_core/standard_error.rb +5 -3
- data/lib/danger/helpers/array_subclass.rb +2 -0
- data/lib/danger/helpers/comment.rb +2 -0
- data/lib/danger/helpers/comments_helper.rb +2 -0
- data/lib/danger/helpers/comments_parsing_helper.rb +6 -3
- data/lib/danger/helpers/emoji_mapper.rb +5 -3
- data/lib/danger/helpers/find_max_num_violations.rb +2 -0
- data/lib/danger/helpers/message_groups_array_helper.rb +2 -0
- data/lib/danger/plugin_support/gems_resolver.rb +2 -0
- data/lib/danger/plugin_support/plugin.rb +2 -0
- data/lib/danger/plugin_support/plugin_file_resolver.rb +3 -1
- data/lib/danger/plugin_support/plugin_linter.rb +8 -6
- data/lib/danger/request_sources/bitbucket_cloud.rb +2 -0
- data/lib/danger/request_sources/bitbucket_cloud_api.rb +2 -2
- data/lib/danger/request_sources/bitbucket_server.rb +3 -1
- data/lib/danger/request_sources/bitbucket_server_api.rb +2 -2
- data/lib/danger/request_sources/code_insights_api.rb +2 -2
- data/lib/danger/request_sources/github/github.rb +71 -11
- data/lib/danger/request_sources/github/github_review.rb +9 -7
- data/lib/danger/request_sources/github/github_review_resolver.rb +2 -0
- data/lib/danger/request_sources/github/github_review_unsupported.rb +2 -0
- data/lib/danger/request_sources/gitlab.rb +17 -18
- data/lib/danger/request_sources/local_only.rb +2 -0
- data/lib/danger/request_sources/request_source.rb +3 -3
- data/lib/danger/request_sources/support/get_ignored_violation.rb +2 -0
- data/lib/danger/request_sources/vsts.rb +2 -1
- data/lib/danger/request_sources/vsts_api.rb +2 -2
- data/lib/danger/scm_source/git_repo.rb +2 -0
- data/lib/danger/version.rb +4 -2
- data/lib/danger.rb +4 -2
- metadata +4 -9
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/plugin_support/plugin"
|
|
2
4
|
|
|
3
5
|
module Danger
|
|
@@ -194,14 +196,14 @@ module Danger
|
|
|
194
196
|
path, line = path.split("#")
|
|
195
197
|
url_path = path.start_with?("/") ? path : "/#{path}"
|
|
196
198
|
text = full_path ? path : File.basename(path)
|
|
197
|
-
url_path.gsub
|
|
199
|
+
url_path = url_path.gsub(" ", "%20")
|
|
198
200
|
line_ref = line ? "##{line}" : ""
|
|
199
201
|
yield("#{repo}#{url_path}?at=#{commit}#{line_ref}", text)
|
|
200
202
|
end
|
|
201
203
|
|
|
202
204
|
return paths.first if paths.count < 2
|
|
203
205
|
|
|
204
|
-
paths.first(paths.count - 1).join(
|
|
206
|
+
"#{paths.first(paths.count - 1).join(', ')} & #{paths.last}"
|
|
205
207
|
end
|
|
206
208
|
|
|
207
209
|
def create_markdown_link(href, text)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/plugin_support/plugin"
|
|
2
4
|
|
|
3
5
|
module Danger
|
|
@@ -231,7 +233,7 @@ module Danger
|
|
|
231
233
|
|
|
232
234
|
return paths.first if paths.count < 2
|
|
233
235
|
|
|
234
|
-
paths.first(paths.count - 1).join(
|
|
236
|
+
"#{paths.first(paths.count - 1).join(', ')} & #{paths.last}"
|
|
235
237
|
end
|
|
236
238
|
|
|
237
239
|
# @!group GitHub Misc
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/plugin_support/plugin"
|
|
2
4
|
|
|
3
5
|
module Danger
|
|
@@ -242,7 +244,7 @@ module Danger
|
|
|
242
244
|
|
|
243
245
|
return paths.first if paths.count < 2
|
|
244
246
|
|
|
245
|
-
paths.first(paths.count - 1).join(
|
|
247
|
+
"#{paths.first(paths.count - 1).join(', ')} & #{paths.last}"
|
|
246
248
|
end
|
|
247
249
|
|
|
248
250
|
# @!group Gitlab Misc
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/danger_core/messages/violation"
|
|
2
4
|
require "danger/danger_core/messages/markdown"
|
|
3
5
|
require "danger/plugin_support/plugin"
|
|
@@ -95,14 +97,30 @@ module Danger
|
|
|
95
97
|
# Optional. Path to the file that the message is for.
|
|
96
98
|
# @option [String] line
|
|
97
99
|
# Optional. The line in the file to present the message in.
|
|
100
|
+
# @option [Integer] start_line
|
|
101
|
+
# Optional. The first line of an inline markdown range.
|
|
102
|
+
# @option [String] side
|
|
103
|
+
# Optional. The side for `line`. Valid values are "LEFT" and "RIGHT".
|
|
104
|
+
# @option [String] start_side
|
|
105
|
+
# Optional. The side for `start_line`. Valid values are "LEFT" and "RIGHT".
|
|
98
106
|
# @return [void]
|
|
99
107
|
#
|
|
100
108
|
def markdown(*markdowns, **options)
|
|
101
109
|
file = options.fetch(:file, nil)
|
|
102
110
|
line = options.fetch(:line, nil)
|
|
111
|
+
start_line = options.fetch(:start_line, nil)
|
|
112
|
+
side = options.fetch(:side, nil)
|
|
113
|
+
start_side = options.fetch(:start_side, nil)
|
|
103
114
|
|
|
104
115
|
markdowns.flatten.each do |markdown|
|
|
105
|
-
@markdowns << Markdown.new(
|
|
116
|
+
@markdowns << Markdown.new(
|
|
117
|
+
markdown,
|
|
118
|
+
file,
|
|
119
|
+
line,
|
|
120
|
+
start_line: start_line,
|
|
121
|
+
side: side,
|
|
122
|
+
start_side: start_side
|
|
123
|
+
)
|
|
106
124
|
end
|
|
107
125
|
end
|
|
108
126
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/plugin_support/plugin"
|
|
2
4
|
|
|
3
5
|
module Danger
|
|
@@ -167,14 +169,14 @@ module Danger
|
|
|
167
169
|
path, line = path.split("#L")
|
|
168
170
|
url_path = path.start_with?("/") ? path : "/#{path}"
|
|
169
171
|
text = full_path ? path : File.basename(path)
|
|
170
|
-
url_path.gsub
|
|
172
|
+
url_path = url_path.gsub(" ", "%20")
|
|
171
173
|
line_ref = line ? "&line=#{line}" : ""
|
|
172
174
|
create_markdown_link("#{repo}/commit/#{commit}?path=#{url_path}&_a=contents#{line_ref}", text)
|
|
173
175
|
end
|
|
174
176
|
|
|
175
177
|
return paths.first if paths.count < 2
|
|
176
178
|
|
|
177
|
-
paths.first(paths.count - 1).join(
|
|
179
|
+
"#{paths.first(paths.count - 1).join(', ')} & #{paths.last}"
|
|
178
180
|
end
|
|
179
181
|
|
|
180
182
|
private
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "claide"
|
|
2
4
|
require "claide/informative_error"
|
|
3
5
|
|
|
@@ -79,7 +81,7 @@ module Danger
|
|
|
79
81
|
# Escape markdown brackets
|
|
80
82
|
description = description.gsub(/<|>/) { |bracket| "\\#{bracket}" }
|
|
81
83
|
|
|
82
|
-
md = "## Danger has errored"
|
|
84
|
+
md = +"## Danger has errored"
|
|
83
85
|
md << "#{description}\n"
|
|
84
86
|
md << "```#{stacktrace}```" if stacktrace
|
|
85
87
|
|
|
@@ -95,7 +97,7 @@ module Danger
|
|
|
95
97
|
trace_line, description = parse_line_number_from_description
|
|
96
98
|
latest_version = Danger.danger_outdated?
|
|
97
99
|
|
|
98
|
-
result[:description] = "\n[!] #{description}"
|
|
100
|
+
result[:description] = +"\n[!] #{description}"
|
|
99
101
|
result[:description] << upgrade_message(latest_version) if latest_version
|
|
100
102
|
|
|
101
103
|
return result unless backtrace && dsl_path && contents
|
|
@@ -112,7 +114,7 @@ module Danger
|
|
|
112
114
|
first_line = line_numer.zero?
|
|
113
115
|
last_line = (line_numer == (lines.count - 1))
|
|
114
116
|
|
|
115
|
-
result[:stacktrace] = "\n"
|
|
117
|
+
result[:stacktrace] = +"\n"
|
|
116
118
|
result[:stacktrace] << "#{indent}from #{trace_line.gsub(/:in.*$/, '')}\n"
|
|
117
119
|
result[:stacktrace] << "#{indent}-------------------------------------------\n"
|
|
118
120
|
result[:stacktrace] << "#{indent}#{lines[line_numer - 1]}" unless first_line
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
module Helpers
|
|
3
5
|
module CommentsParsingHelper
|
|
@@ -43,11 +45,12 @@ module Danger
|
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
def table_kind_from_title(title)
|
|
46
|
-
|
|
48
|
+
case title
|
|
49
|
+
when /error/i
|
|
47
50
|
:error
|
|
48
|
-
|
|
51
|
+
when /warning/i
|
|
49
52
|
:warning
|
|
50
|
-
|
|
53
|
+
when /message/i
|
|
51
54
|
:message
|
|
52
55
|
end
|
|
53
56
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
class EmojiMapper
|
|
3
5
|
DATA = {
|
|
@@ -22,12 +24,12 @@ module Danger
|
|
|
22
24
|
}.freeze
|
|
23
25
|
|
|
24
26
|
def initialize(template)
|
|
25
|
-
@template = DATA.
|
|
27
|
+
@template = DATA.key?(template) ? template : "github"
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def map(emoji)
|
|
29
|
-
emoji&.delete
|
|
30
|
-
DATA[template][
|
|
31
|
+
cleaned_emoji = emoji&.delete(":") || emoji
|
|
32
|
+
DATA[template][cleaned_emoji]
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def from_type(type)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/plugin_support/gems_resolver"
|
|
2
4
|
|
|
3
5
|
module Danger
|
|
@@ -14,7 +16,7 @@ module Danger
|
|
|
14
16
|
def resolve
|
|
15
17
|
if !refs.nil? and refs.select { |ref| File.file? ref }.any?
|
|
16
18
|
paths = refs.select { |ref| File.file? ref }.map { |path| File.expand_path(path) }
|
|
17
|
-
elsif refs
|
|
19
|
+
elsif refs.kind_of? Array
|
|
18
20
|
paths, gems = GemsResolver.new(refs).call
|
|
19
21
|
else
|
|
20
22
|
paths = Dir.glob(File.join(".", "lib/**/*.rb")).map { |path| File.expand_path(path) }
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
class PluginLinter
|
|
3
5
|
# An internal class that is used to represent a rule for the linter.
|
|
@@ -13,7 +15,7 @@ module Danger
|
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def object_applied_to
|
|
16
|
-
metadata[:name].to_s.bold
|
|
18
|
+
"#{metadata[:name].to_s.bold} (#{type})"
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
@@ -115,10 +117,10 @@ module Danger
|
|
|
115
117
|
json[:body_md] && json[:body_md].empty?
|
|
116
118
|
end),
|
|
117
119
|
Rule.new(:warning, 43..45, "Params", "You should give a 'type' for the param, yes, ruby is duck-typey but it's useful for newbies to the language, use `@param [Type] name`.", proc do |json|
|
|
118
|
-
json[:param_couplets]
|
|
120
|
+
json[:param_couplets]&.flat_map(&:values)&.include?(nil)
|
|
119
121
|
end),
|
|
120
122
|
Rule.new(:warning, 43..45, "Unknown Param", "You should give a 'type' for the param, yes, ruby is duck-typey but it's useful for newbies to the language, use `@param [Type] name`.", proc do |json|
|
|
121
|
-
json[:param_couplets]
|
|
123
|
+
json[:param_couplets]&.flat_map(&:values)&.include?("Unknown")
|
|
122
124
|
end),
|
|
123
125
|
Rule.new(:warning, 46, "Return Type", "If the function has no useful return value, use ` @return [void]` - this will be ignored by documentation generators.", proc do |json|
|
|
124
126
|
return_hash = json[:tags].find { |tag| tag[:name] == "return" }
|
|
@@ -131,11 +133,11 @@ module Danger
|
|
|
131
133
|
#
|
|
132
134
|
def link(ref)
|
|
133
135
|
if ref.kind_of?(Range)
|
|
134
|
-
"@see - "
|
|
136
|
+
"@see - #{"https://github.com/dbgrandi/danger-prose/blob/v2.0.0/lib/danger_plugin.rb#L#{ref.min}#-L#{ref.max}".blue}"
|
|
135
137
|
elsif ref.kind_of?(Integer)
|
|
136
|
-
"@see - "
|
|
138
|
+
"@see - #{"https://github.com/dbgrandi/danger-prose/blob/v2.0.0/lib/danger_plugin.rb#L#{ref}".blue}"
|
|
137
139
|
else
|
|
138
|
-
"@see -
|
|
140
|
+
"@see - #{'https://github.com/dbgrandi/danger-prose/blob/v2.0.0/lib/danger_plugin.rb'.blue}"
|
|
139
141
|
end
|
|
140
142
|
end
|
|
141
143
|
|
|
@@ -32,8 +32,8 @@ module Danger
|
|
|
32
32
|
def inspect
|
|
33
33
|
inspected = super
|
|
34
34
|
|
|
35
|
-
inspected.gsub
|
|
36
|
-
inspected.gsub
|
|
35
|
+
inspected = inspected.gsub(@password, "********") if @password
|
|
36
|
+
inspected = inspected.gsub(@access_token, "********") if @access_token
|
|
37
37
|
|
|
38
38
|
inspected
|
|
39
39
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/helpers/comments_helper"
|
|
2
4
|
require "danger/request_sources/bitbucket_server_api"
|
|
3
5
|
require "danger/request_sources/code_insights_api"
|
|
@@ -179,7 +181,7 @@ module Danger
|
|
|
179
181
|
changeset = self.pr_json[:fromRef][:latestCommit]
|
|
180
182
|
# Support for older versions of Bitbucket Server
|
|
181
183
|
changeset = self.pr_json[:fromRef][:latestChangeset] if self.pr_json[:fromRef].key? :latestChangeset
|
|
182
|
-
puts "Changeset: "
|
|
184
|
+
puts "Changeset: #{changeset}"
|
|
183
185
|
puts self.pr_json.to_json
|
|
184
186
|
@api.update_pr_build_status(status, changeset, build_job_link, description)
|
|
185
187
|
end
|
|
@@ -14,7 +14,7 @@ module Danger
|
|
|
14
14
|
self.host = environment["DANGER_BITBUCKETSERVER_HOST"]
|
|
15
15
|
self.verify_ssl = environment["DANGER_BITBUCKETSERVER_VERIFY_SSL"] != "false"
|
|
16
16
|
if self.host && !(self.host.include? "http://") && !(self.host.include? "https://")
|
|
17
|
-
self.host = "https
|
|
17
|
+
self.host = "https://#{self.host}"
|
|
18
18
|
end
|
|
19
19
|
self.key = slug
|
|
20
20
|
self.project = project
|
|
@@ -24,7 +24,7 @@ module Danger
|
|
|
24
24
|
def inspect
|
|
25
25
|
inspected = super
|
|
26
26
|
|
|
27
|
-
inspected.gsub
|
|
27
|
+
inspected = inspected.gsub(@password, "********") if @password
|
|
28
28
|
|
|
29
29
|
inspected
|
|
30
30
|
end
|
|
@@ -26,7 +26,7 @@ module Danger
|
|
|
26
26
|
def inspect
|
|
27
27
|
inspected = super
|
|
28
28
|
|
|
29
|
-
inspected.gsub
|
|
29
|
+
inspected = inspected.gsub(@password, "********") if @password
|
|
30
30
|
|
|
31
31
|
inspected
|
|
32
32
|
end
|
|
@@ -131,7 +131,7 @@ module Danger
|
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
def annotation_endpoint_at_commit(commit)
|
|
134
|
-
report_endpoint_at_commit(commit)
|
|
134
|
+
"#{report_endpoint_at_commit(commit)}/annotations"
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
def use_ssl
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# rubocop:disable Metrics/ClassLength
|
|
2
4
|
|
|
3
5
|
require "octokit"
|
|
@@ -12,6 +14,8 @@ module Danger
|
|
|
12
14
|
class GitHub < RequestSource
|
|
13
15
|
include Danger::Helpers::CommentsHelper
|
|
14
16
|
|
|
17
|
+
DiffLineReference = Struct.new(:file, :line)
|
|
18
|
+
|
|
15
19
|
attr_accessor :pr_json, :issue_json, :use_local_git, :support_tokenless_auth, :dismiss_out_of_range_messages, :host, :api_url, :verify_ssl
|
|
16
20
|
|
|
17
21
|
def self.env_vars
|
|
@@ -32,9 +36,7 @@ module Danger
|
|
|
32
36
|
# backwards compatibility. `DANGER_GITHUB_API_BASE_URL` is the new
|
|
33
37
|
# correctly named variable.
|
|
34
38
|
self.api_url = environment.fetch("DANGER_GITHUB_API_HOST") do
|
|
35
|
-
environment.fetch("DANGER_GITHUB_API_BASE_URL")
|
|
36
|
-
"https://api.github.com/".freeze
|
|
37
|
-
end
|
|
39
|
+
environment.fetch("DANGER_GITHUB_API_BASE_URL", "https://api.github.com/")
|
|
38
40
|
end
|
|
39
41
|
self.verify_ssl = environment["DANGER_OCTOKIT_VERIFY_SSL"] != "false"
|
|
40
42
|
|
|
@@ -333,9 +335,10 @@ module Danger
|
|
|
333
335
|
next false unless m.file && m.line
|
|
334
336
|
|
|
335
337
|
position = find_position_in_diff diff_lines, m, kind
|
|
338
|
+
start_position = start_position_in_diff(diff_lines, m, kind)
|
|
336
339
|
|
|
337
340
|
# Keep the change if it's line is not in the diff and not in dismiss mode
|
|
338
|
-
next dismiss_out_of_range_messages_for(kind) if position.nil?
|
|
341
|
+
next dismiss_out_of_range_messages_for(kind) if position.nil? || start_position == :out_of_range
|
|
339
342
|
|
|
340
343
|
# Once we know we're gonna submit it, we format it
|
|
341
344
|
if is_markdown_content
|
|
@@ -350,7 +353,7 @@ module Danger
|
|
|
350
353
|
end
|
|
351
354
|
|
|
352
355
|
matching_comments = danger_comments.select do |comment_data|
|
|
353
|
-
if comment_data
|
|
356
|
+
if inline_comment_matches?(comment_data, m, position)
|
|
354
357
|
# Parse it to avoid problems with strikethrough
|
|
355
358
|
violation = violations_from_table(comment_data["body"]).first
|
|
356
359
|
if violation
|
|
@@ -366,10 +369,7 @@ module Danger
|
|
|
366
369
|
|
|
367
370
|
if matching_comments.empty?
|
|
368
371
|
begin
|
|
369
|
-
|
|
370
|
-
# See https://github.com/danger/danger/issues/1475 for detailed information.
|
|
371
|
-
client.create_pull_request_comment(ci_source.repo_slug, ci_source.pull_request_id,
|
|
372
|
-
body, head_ref, m.file, (Octokit::MAJOR >= 8 ? m.line : position))
|
|
372
|
+
create_inline_comment(body, head_ref, m, position)
|
|
373
373
|
rescue Octokit::UnprocessableEntity => e
|
|
374
374
|
# Show more detail for UnprocessableEntity error
|
|
375
375
|
message = [e, "body: #{body}", "head_ref: #{head_ref}", "filename: #{m.file}", "position: #{position}"].join("\n")
|
|
@@ -392,16 +392,76 @@ module Danger
|
|
|
392
392
|
end
|
|
393
393
|
end
|
|
394
394
|
|
|
395
|
+
def start_position_in_diff(diff_lines, message, kind)
|
|
396
|
+
return nil unless ranged_inline_comment?(message)
|
|
397
|
+
|
|
398
|
+
start_message = DiffLineReference.new(message.file, message.start_line)
|
|
399
|
+
find_position_in_diff(diff_lines, start_message, kind) || :out_of_range
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
def inline_comment_matches?(comment_data, message, position)
|
|
403
|
+
return false unless comment_data["path"] == message.file
|
|
404
|
+
|
|
405
|
+
if ranged_inline_comment?(message)
|
|
406
|
+
ranged_inline_comment_lines_match?(comment_data, message)
|
|
407
|
+
else
|
|
408
|
+
comment_data["position"] == position
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
def create_inline_comment(body, head_ref, message, position)
|
|
413
|
+
# Since Octokit v8, the signature of create_pull_request_comment has been changed.
|
|
414
|
+
# See https://github.com/danger/danger/issues/1475 for detailed information.
|
|
415
|
+
if ranged_inline_comment?(message) && Octokit::MAJOR >= 8
|
|
416
|
+
# GitHub ranges are required for multi-line suggestion blocks that
|
|
417
|
+
# replace an existing added translator comment plus the added string.
|
|
418
|
+
client.create_pull_request_comment(
|
|
419
|
+
ci_source.repo_slug,
|
|
420
|
+
ci_source.pull_request_id,
|
|
421
|
+
body,
|
|
422
|
+
head_ref,
|
|
423
|
+
message.file,
|
|
424
|
+
message.line,
|
|
425
|
+
start_line: message.start_line,
|
|
426
|
+
side: message.side || "RIGHT",
|
|
427
|
+
start_side: message.start_side || "RIGHT"
|
|
428
|
+
)
|
|
429
|
+
else
|
|
430
|
+
# Octokit v7 only supports diff positions, so ranged metadata is ignored.
|
|
431
|
+
client.create_pull_request_comment(
|
|
432
|
+
ci_source.repo_slug,
|
|
433
|
+
ci_source.pull_request_id,
|
|
434
|
+
body,
|
|
435
|
+
head_ref,
|
|
436
|
+
message.file,
|
|
437
|
+
(Octokit::MAJOR >= 8 ? message.line : position)
|
|
438
|
+
)
|
|
439
|
+
end
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
def ranged_inline_comment?(message)
|
|
443
|
+
!message.start_line.nil?
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
def ranged_inline_comment_lines_match?(comment_data, message)
|
|
447
|
+
comment_line = comment_data["line"]
|
|
448
|
+
comment_start_line = comment_data["start_line"]
|
|
449
|
+
return false if comment_line.nil? || comment_start_line.nil?
|
|
450
|
+
|
|
451
|
+
comment_line.to_i == message.line &&
|
|
452
|
+
comment_start_line.to_i == message.start_line
|
|
453
|
+
end
|
|
454
|
+
|
|
395
455
|
def find_position_in_diff(diff_lines, message, kind)
|
|
396
456
|
range_header_regexp = /@@ -([0-9]+)(,([0-9]+))? \+(?<start>[0-9]+)(,(?<end>[0-9]+))? @@.*/
|
|
397
457
|
file_header_regexp = %r{^diff --git a/.*}
|
|
398
458
|
|
|
399
|
-
pattern = "+++ b
|
|
459
|
+
pattern = "+++ b/#{message.file}\n"
|
|
400
460
|
file_start = diff_lines.index(pattern)
|
|
401
461
|
|
|
402
462
|
# Files containing spaces sometimes have a trailing tab
|
|
403
463
|
if file_start.nil?
|
|
404
|
-
pattern = "+++ b
|
|
464
|
+
pattern = "+++ b/#{message.file}\t\n"
|
|
405
465
|
file_start = diff_lines.index(pattern)
|
|
406
466
|
end
|
|
407
467
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "octokit"
|
|
2
4
|
require "danger/ci_source/ci_source"
|
|
3
5
|
require "danger/request_sources/github/github_review_resolver"
|
|
@@ -13,15 +15,15 @@ module Danger
|
|
|
13
15
|
include Danger::Helpers::CommentsHelper
|
|
14
16
|
|
|
15
17
|
# @see https://developer.github.com/v3/pulls/reviews/ for all possible events
|
|
16
|
-
EVENT_APPROVE = "APPROVE"
|
|
17
|
-
EVENT_REQUEST_CHANGES = "REQUEST_CHANGES"
|
|
18
|
-
EVENT_COMMENT = "COMMENT"
|
|
18
|
+
EVENT_APPROVE = "APPROVE"
|
|
19
|
+
EVENT_REQUEST_CHANGES = "REQUEST_CHANGES"
|
|
20
|
+
EVENT_COMMENT = "COMMENT"
|
|
19
21
|
|
|
20
22
|
# Current review status, if the review has not been submitted yet -> STATUS_PENDING
|
|
21
|
-
STATUS_APPROVED = "APPROVED"
|
|
22
|
-
STATUS_REQUESTED_CHANGES = "CHANGES_REQUESTED"
|
|
23
|
-
STATUS_COMMENTED = "COMMENTED"
|
|
24
|
-
STATUS_PENDING = "PENDING"
|
|
23
|
+
STATUS_APPROVED = "APPROVED"
|
|
24
|
+
STATUS_REQUESTED_CHANGES = "CHANGES_REQUESTED"
|
|
25
|
+
STATUS_COMMENTED = "COMMENTED"
|
|
26
|
+
STATUS_PENDING = "PENDING"
|
|
25
27
|
|
|
26
28
|
attr_reader :id, :body, :status, :review_json
|
|
27
29
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "uri"
|
|
2
4
|
require "danger/helpers/comments_helper"
|
|
3
5
|
require "danger/helpers/comment"
|
|
@@ -71,18 +73,16 @@ module Danger
|
|
|
71
73
|
def mr_comments
|
|
72
74
|
# @raw_comments contains what we got back from the server.
|
|
73
75
|
# @comments contains Comment objects (that have less information)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
.map { |comment| Comment.from_gitlab(comment) }
|
|
85
|
-
end
|
|
76
|
+
if supports_inline_comments
|
|
77
|
+
@raw_comments = mr_discussions
|
|
78
|
+
.auto_paginate
|
|
79
|
+
.flat_map { |discussion| discussion.notes.map { |note| note.to_h.merge({ "discussion_id" => discussion.id }) } }
|
|
80
|
+
else
|
|
81
|
+
@raw_comments = client.merge_request_comments(ci_source.repo_slug, ci_source.pull_request_id, per_page: 100)
|
|
82
|
+
.auto_paginate
|
|
83
|
+
end
|
|
84
|
+
@comments ||= @raw_comments
|
|
85
|
+
.map { |comment| Comment.from_gitlab(comment) }
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def mr_discussions
|
|
@@ -216,12 +216,11 @@ module Danger
|
|
|
216
216
|
previous_violations: previous_violations
|
|
217
217
|
}.merge(main_violations))
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
end
|
|
219
|
+
if should_create_new_comment
|
|
220
|
+
client.create_merge_request_note(ci_source.repo_slug, ci_source.pull_request_id, body)
|
|
221
|
+
else
|
|
222
|
+
client.edit_merge_request_note(ci_source.repo_slug, ci_source.pull_request_id, last_comment.id, body)
|
|
223
|
+
end
|
|
225
224
|
end
|
|
226
225
|
end
|
|
227
226
|
|
|
@@ -41,9 +41,9 @@ module Danger
|
|
|
41
41
|
def inspect
|
|
42
42
|
inspected = super
|
|
43
43
|
|
|
44
|
-
inspected.gsub
|
|
45
|
-
inspected.gsub
|
|
46
|
-
inspected.gsub
|
|
44
|
+
inspected = inspected.gsub(@token, "********") if @token
|
|
45
|
+
inspected = inspected.gsub(@access_token, "********") if @access_token
|
|
46
|
+
inspected = inspected.gsub(@bearer_token, "********") if @bearer_token
|
|
47
47
|
|
|
48
48
|
inspected
|
|
49
49
|
end
|