danger 6.3.1 → 6.3.2
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/bitrise.rb +10 -7
- data/lib/danger/ci_source/github_actions.rb +8 -15
- data/lib/danger/comment_generators/bitbucket_server_inline.md.erb +1 -1
- data/lib/danger/danger_core/dangerfile.rb +17 -11
- data/lib/danger/danger_core/message_aggregator.rb +12 -0
- data/lib/danger/danger_core/message_group.rb +42 -0
- data/lib/danger/danger_core/messages/base.rb +56 -0
- data/lib/danger/danger_core/messages/markdown.rb +11 -14
- data/lib/danger/danger_core/messages/violation.rb +17 -12
- data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +3 -3
- data/lib/danger/helpers/comments_helper.rb +1 -1
- data/lib/danger/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27b09c31a2f456489426bf90c66b907f7c7b620bc0019387c3c7dd89e14267b6
|
4
|
+
data.tar.gz: 7aeed8d94b83e5fb757ca0f319fe55e3c07a4fc641c93dd56408efc1aaeccf4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 267bc39cef40d450ec1be77ddeb0c279ef6b5b7f5cd8a3dd2afdb49f6a4b5fa32feb10622c84f0f2f85a3907b4fb05824ecfad0b517fcf4eacd0d4949423dc69
|
7
|
+
data.tar.gz: de72c74f898bdc9a3c70bf730158e2c642aa6b392935a3e89a6980a457262475c549f10380e0123e4a5b92c03ae9b27018bf7cb8aa919667256edd5639d70149
|
@@ -21,7 +21,7 @@ module Danger
|
|
21
21
|
#
|
22
22
|
# ### bitbucket server and bitrsie
|
23
23
|
#
|
24
|
-
# Danger will read the
|
24
|
+
# Danger will read the environment variable GIT_REPOSITORY_URL to construct the Bitbucket Server API URL
|
25
25
|
# finding the project and repo slug in the GIT_REPOSITORY_URL variable. This GIT_REPOSITORY_URL variable
|
26
26
|
# comes from the App Settings tab for your Bitrsie App. If you are manually setting a repo URL in the
|
27
27
|
# Git Clone Repo step, you may need to set adjust this propery in the settings tab, maybe even fake it.
|
@@ -48,13 +48,16 @@ module Danger
|
|
48
48
|
def initialize(env)
|
49
49
|
self.pull_request_id = env["BITRISE_PULL_REQUEST"]
|
50
50
|
self.repo_url = env["GIT_REPOSITORY_URL"]
|
51
|
-
|
52
|
-
if repo_url.include? ".com/"
|
53
|
-
repo_matches = self.repo_url.match(%r{\.com/(.*)})[1].split(/\.git$|$/)[0]
|
54
|
-
elsif repo_url.include? ".com:"
|
55
|
-
repo_matches = self.repo_url.match(%r{\.com:(.*)})[1].split(/\.git$|$/)[0]
|
56
|
-
end
|
57
51
|
|
52
|
+
matcher_url = self.repo_url
|
53
|
+
|
54
|
+
#If the URL contains https:// as :// leads to inaccurate matching. So we remove it and proceed to match.
|
55
|
+
if repo_url.include? "https://"
|
56
|
+
matcher_url["https://"] = ''
|
57
|
+
end
|
58
|
+
|
59
|
+
repo_matches = matcher_url.match(%r{([\/:])(([^\/]+\/)+[^\/]+?)(\.git$|$)})[2]
|
60
|
+
|
58
61
|
self.repo_slug = repo_matches unless repo_matches.nil?
|
59
62
|
|
60
63
|
end
|
@@ -3,25 +3,18 @@ require "danger/request_sources/github/github"
|
|
3
3
|
module Danger
|
4
4
|
# ### CI Setup
|
5
5
|
#
|
6
|
-
# You can use `danger/danger` Action in your
|
6
|
+
# You can use `danger/danger` Action in your `.github/workflows/xxx.yml`.
|
7
|
+
# And so, you can use GITHUB_TOKEN secret as `DANGER_GITHUB_API_TOKEN` environment variable.
|
7
8
|
#
|
8
9
|
# ```
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
10
|
+
# ...
|
11
|
+
# steps:
|
12
|
+
# - uses: actions/checkout@v1
|
13
|
+
# - uses: danger/danger@master
|
14
|
+
# env:
|
15
|
+
# DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
12
16
|
# ```
|
13
17
|
#
|
14
|
-
# ### Token Setup
|
15
|
-
#
|
16
|
-
# Set DANGER_GITHUB_API_TOKEN to secrets, or you can also use GITHUB_TOKEN.
|
17
|
-
#
|
18
|
-
# ```
|
19
|
-
# action "Danger" {
|
20
|
-
# uses = "danger/danger"
|
21
|
-
# secrets = ["GITHUB_TOKEN"]
|
22
|
-
# }
|
23
|
-
# ```
|
24
|
-
#
|
25
18
|
class GitHubActions < CI
|
26
19
|
def self.validates_as_ci?(env)
|
27
20
|
env.key? "GITHUB_ACTION"
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<%- table[:content].each do |violation| -%>
|
3
3
|
<%= @emoji_mapper.map(table[:emoji]) if table[:emoji] %> <%= violation.message %>
|
4
4
|
<%- end -%>
|
5
|
-
<%- table[:resolved].each do |message| -%>
|
5
|
+
<%- table[:resolved] && table[:resolved].each do |message| -%>
|
6
6
|
<%= @emoji_mapper.map("white_check_mark") %> <%= message %>
|
7
7
|
<%- end -%>
|
8
8
|
<%- end -%>
|
@@ -60,7 +60,6 @@ module Danger
|
|
60
60
|
# that the core DSLs have, then starts looking at plugins support.
|
61
61
|
|
62
62
|
# rubocop:disable Style/MethodMissing
|
63
|
-
|
64
63
|
def method_missing(method_sym, *arguments, &_block)
|
65
64
|
@core_plugins.each do |plugin|
|
66
65
|
if plugin.public_methods(false).include?(method_sym)
|
@@ -243,16 +242,23 @@ module Danger
|
|
243
242
|
|
244
243
|
def post_results(danger_id, new_comment, remove_previous_comments)
|
245
244
|
violations = violation_report
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
245
|
+
report = {
|
246
|
+
warnings: violations[:warnings].uniq,
|
247
|
+
errors: violations[:errors].uniq,
|
248
|
+
messages: violations[:messages].uniq,
|
249
|
+
markdowns: status_report[:markdowns].uniq,
|
250
|
+
danger_id: danger_id
|
251
|
+
}
|
252
|
+
|
253
|
+
if env.request_source.respond_to?(:update_pr_by_line!) && ENV["DANGER_MESSAGE_AGGREGATION"]
|
254
|
+
env.request_source.update_pr_by_line!(messages: MessageAggregator.aggregate(**report))
|
255
|
+
else
|
256
|
+
env.request_source.update_pull_request!(
|
257
|
+
**report,
|
258
|
+
new_comment: new_comment,
|
259
|
+
remove_previous_comments: remove_previous_comments
|
260
|
+
)
|
261
|
+
end
|
256
262
|
end
|
257
263
|
|
258
264
|
def setup_for_running(base_branch, head_branch)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Danger
|
4
|
+
class MessageGroup
|
5
|
+
def initialize(file: nil, line: nil)
|
6
|
+
@file = file
|
7
|
+
@line = line
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns whether this `MessageGroup` is for the same line of code as
|
11
|
+
# `other`, taking which file they are in to account.
|
12
|
+
# @param other [MessageGroup, Markdown, Violation]
|
13
|
+
# @return [Boolean] whether this `MessageGroup` is for the same line of code
|
14
|
+
def same_line?(other)
|
15
|
+
other.file == file && other.line == line
|
16
|
+
end
|
17
|
+
|
18
|
+
# Merges two `MessageGroup`s that represent the same line of code
|
19
|
+
# In future, perhaps `MessageGroup` will be able to represent a group of
|
20
|
+
# messages for multiple lines.
|
21
|
+
def merge(other)
|
22
|
+
raise ArgumentError, "Cannot merge with MessageGroup for a different line" unless same_line?(other)
|
23
|
+
|
24
|
+
@messages = (messages + other.messages).uniq
|
25
|
+
end
|
26
|
+
|
27
|
+
# Adds a message to the group.
|
28
|
+
# @param message [Markdown, Violation] the message to add
|
29
|
+
def <<(message)
|
30
|
+
# TODO: insertion sort
|
31
|
+
messages << message if same_line?(message)
|
32
|
+
end
|
33
|
+
|
34
|
+
# The list of messages in this group. This list will be sorted in decreasing
|
35
|
+
# order of severity (error, warning, message, markdown)
|
36
|
+
def messages
|
37
|
+
@messages ||= []
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_reader :file, :line
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Danger
|
2
|
+
class BaseMessage
|
3
|
+
attr_accessor :message, :file, :line, :type
|
4
|
+
|
5
|
+
def initialize(type:, message:, file: nil, line: nil)
|
6
|
+
@type = type
|
7
|
+
@message = message
|
8
|
+
@file = file
|
9
|
+
@line = line
|
10
|
+
end
|
11
|
+
|
12
|
+
def compare_by_file_and_line(other)
|
13
|
+
order = cmp_nils(file, other.file)
|
14
|
+
return order unless order.nil?
|
15
|
+
|
16
|
+
order = file <=> other.file
|
17
|
+
return order unless order.zero?
|
18
|
+
|
19
|
+
order = cmp_nils(line, other.line)
|
20
|
+
return order unless order.nil?
|
21
|
+
|
22
|
+
line <=> other.line
|
23
|
+
end
|
24
|
+
# compares a and b based entirely on whether one or the other is nil
|
25
|
+
# arguments are in the same order as `a <=> b`
|
26
|
+
# nil is sorted earlier - so cmp_nils(nil, 1) => -1
|
27
|
+
#
|
28
|
+
# If neither are nil, rather than returning `a <=> b` which would seem
|
29
|
+
# like the obvious shortcut, `nil` is returned.
|
30
|
+
# This allows us to distinguish between cmp_nils returning 0 for a
|
31
|
+
# comparison of filenames, which means "a comparison on the lines is
|
32
|
+
# meaningless - you cannot have a line number for a nil file - so they
|
33
|
+
# should be sorted the same", and a <=> b returning 0, which means "the
|
34
|
+
# files are the same, so compare on the lines"
|
35
|
+
#
|
36
|
+
# @return 0, 1, -1, or nil
|
37
|
+
def cmp_nils(a, b)
|
38
|
+
if a.nil? && b.nil?
|
39
|
+
0
|
40
|
+
elsif a.nil?
|
41
|
+
-1
|
42
|
+
elsif b.nil?
|
43
|
+
1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def eql?(other)
|
48
|
+
return self == other
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Boolean] returns true if is a file or line, false otherwise
|
52
|
+
def inline?
|
53
|
+
file || line
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "danger/danger_core/messages/base"
|
3
|
+
|
1
4
|
module Danger
|
2
|
-
class Markdown
|
3
|
-
attr_accessor :message, :file, :line
|
5
|
+
class Markdown < BaseMessage
|
4
6
|
|
5
7
|
def initialize(message, file = nil, line = nil)
|
6
|
-
|
7
|
-
self.file = file
|
8
|
-
self.line = line
|
8
|
+
super(type: :markdown, message: message, file: file, line: line)
|
9
9
|
end
|
10
10
|
|
11
11
|
def ==(other)
|
@@ -25,15 +25,6 @@ module Danger
|
|
25
25
|
h
|
26
26
|
end
|
27
27
|
|
28
|
-
def eql?(other)
|
29
|
-
return self == other
|
30
|
-
end
|
31
|
-
|
32
|
-
# @return [Boolean] returns true if is a file or line, false otherwise
|
33
|
-
def inline?
|
34
|
-
file || line
|
35
|
-
end
|
36
|
-
|
37
28
|
def to_s
|
38
29
|
extra = []
|
39
30
|
extra << "file: #{file}" unless file
|
@@ -41,5 +32,11 @@ module Danger
|
|
41
32
|
|
42
33
|
"Markdown #{message} { #{extra.join ', '.freeze} }"
|
43
34
|
end
|
35
|
+
|
36
|
+
def <=>(other)
|
37
|
+
return 1 if other.type != :markdown
|
38
|
+
|
39
|
+
compare_by_file_and_line(other)
|
40
|
+
end
|
44
41
|
end
|
45
42
|
end
|
@@ -1,12 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "danger/danger_core/messages/base"
|
4
|
+
|
1
5
|
module Danger
|
2
|
-
class Violation
|
3
|
-
|
6
|
+
class Violation < BaseMessage
|
7
|
+
VALID_TYPES = %I[error warning message].freeze
|
8
|
+
attr_accessor :sticky
|
4
9
|
|
5
|
-
def initialize(message, sticky, file = nil, line = nil)
|
6
|
-
|
10
|
+
def initialize(message, sticky, file = nil, line = nil, type: :warning)
|
11
|
+
raise ArgumentError unless VALID_TYPES.include?(type)
|
12
|
+
|
13
|
+
super(type: type, message: message, file: file, line: line)
|
7
14
|
self.sticky = sticky
|
8
|
-
self.file = file
|
9
|
-
self.line = line
|
10
15
|
end
|
11
16
|
|
12
17
|
def ==(other)
|
@@ -28,13 +33,12 @@ module Danger
|
|
28
33
|
h
|
29
34
|
end
|
30
35
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
36
|
+
def <=>(other)
|
37
|
+
types = VALID_TYPES + [:markdown]
|
38
|
+
order = types.index(type) <=> types.index(other.type)
|
39
|
+
return order unless order.zero?
|
34
40
|
|
35
|
-
|
36
|
-
def inline?
|
37
|
-
file || line
|
41
|
+
compare_by_file_and_line(other)
|
38
42
|
end
|
39
43
|
|
40
44
|
def to_s
|
@@ -42,6 +46,7 @@ module Danger
|
|
42
46
|
extra << "sticky: #{sticky}"
|
43
47
|
extra << "file: #{file}" if file
|
44
48
|
extra << "line: #{line}" if line
|
49
|
+
extra << "type: #{type}"
|
45
50
|
|
46
51
|
"Violation #{message} { #{extra.join ', '.freeze} }"
|
47
52
|
end
|
@@ -124,7 +124,7 @@ module Danger
|
|
124
124
|
line = options.fetch(:line, nil)
|
125
125
|
|
126
126
|
messages.flatten.each do |message|
|
127
|
-
@messages << Violation.new(message, sticky, file, line) if message
|
127
|
+
@messages << Violation.new(message, sticky, file, line, type: :message) if message
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
@@ -149,7 +149,7 @@ module Danger
|
|
149
149
|
|
150
150
|
warnings.flatten.each do |warning|
|
151
151
|
next if should_ignore_violation(warning)
|
152
|
-
@warnings << Violation.new(warning, sticky, file, line) if warning
|
152
|
+
@warnings << Violation.new(warning, sticky, file, line, type: :warning) if warning
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
@@ -174,7 +174,7 @@ module Danger
|
|
174
174
|
|
175
175
|
failures.flatten.each do |failure|
|
176
176
|
next if should_ignore_violation(failure)
|
177
|
-
@errors << Violation.new(failure, sticky, file, line) if failure
|
177
|
+
@errors << Violation.new(failure, sticky, file, line, type: :error) if failure
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
@@ -104,7 +104,7 @@ module Danger
|
|
104
104
|
)
|
105
105
|
end
|
106
106
|
|
107
|
-
def generate_inline_comment_body(emoji, message, danger_id: "danger", resolved:
|
107
|
+
def generate_inline_comment_body(emoji, message, danger_id: "danger", resolved: false, template: "github")
|
108
108
|
apply_template(
|
109
109
|
tables: [{ content: [message], resolved: resolved, emoji: emoji }],
|
110
110
|
danger_id: danger_id,
|
data/lib/danger/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.3.
|
4
|
+
version: 6.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Orta Therox
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-03-
|
12
|
+
date: 2020-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: claide
|
@@ -262,6 +262,9 @@ files:
|
|
262
262
|
- lib/danger/danger_core/dangerfile_generator.rb
|
263
263
|
- lib/danger/danger_core/environment_manager.rb
|
264
264
|
- lib/danger/danger_core/executor.rb
|
265
|
+
- lib/danger/danger_core/message_aggregator.rb
|
266
|
+
- lib/danger/danger_core/message_group.rb
|
267
|
+
- lib/danger/danger_core/messages/base.rb
|
265
268
|
- lib/danger/danger_core/messages/markdown.rb
|
266
269
|
- lib/danger/danger_core/messages/violation.rb
|
267
270
|
- lib/danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin.rb
|