danger 9.4.2 → 9.5.3
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/README.md +2 -2
- data/lib/danger/ci_source/azure_pipelines.rb +1 -1
- data/lib/danger/ci_source/bitbucket_pipelines.rb +24 -3
- data/lib/danger/ci_source/bitrise.rb +4 -4
- data/lib/danger/ci_source/buildkite.rb +1 -1
- data/lib/danger/ci_source/code_build.rb +2 -2
- data/lib/danger/ci_source/local_git_repo.rb +0 -1
- data/lib/danger/commands/pr.rb +0 -1
- data/lib/danger/danger_core/environment_manager.rb +3 -1
- data/lib/danger/danger_core/message_aggregator.rb +2 -2
- data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +1 -1
- data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +1 -1
- data/lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb +25 -20
- data/lib/danger/helpers/comments_helper.rb +6 -4
- data/lib/danger/helpers/comments_parsing_helper.rb +3 -1
- data/lib/danger/request_sources/bitbucket_cloud.rb +13 -6
- data/lib/danger/request_sources/bitbucket_cloud_api.rb +8 -0
- data/lib/danger/request_sources/bitbucket_server.rb +1 -1
- data/lib/danger/request_sources/github/github.rb +39 -14
- data/lib/danger/request_sources/gitlab.rb +2 -2
- data/lib/danger/request_sources/vsts.rb +2 -2
- data/lib/danger/scm_source/git_repo.rb +5 -2
- data/lib/danger/version.rb +1 -1
- metadata +53 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c1a29ac64cb5013e28a0e137ba85672f035a3116508c15815ff34e2e4c2efe71
|
|
4
|
+
data.tar.gz: ccd8f3bf454de07224648c91fcff6f4e63d8173b50215d769de44230b4621e16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 11a8ad39bcfbddb55c4683e7a7852d79ac17f74f5da55dcfabc796ac4b83a5f4b45d2ad5de53cc8bfdb47034c0572d546ff225b021c4420a751c3d9e0cd9962e
|
|
7
|
+
data.tar.gz: 6dd015355fb17c8bf4a4f79eec81e4e755b1e6eb94268d55809f4146b41367ed474969ce08358e8ef2deb05998af89ec04414ae0caed6407ff28ef24c374452d
|
data/README.md
CHANGED
|
@@ -19,11 +19,11 @@ Formalize your Pull Request etiquette.
|
|
|
19
19
|
|
|
20
20
|
## What is Danger?
|
|
21
21
|
|
|
22
|
-
Danger runs
|
|
22
|
+
Danger runs during your CI process, and gives teams the chance to automate common code review chores.
|
|
23
23
|
|
|
24
24
|
This provides another logical step in your process, through this Danger can help lint your rote tasks in daily code review.
|
|
25
25
|
|
|
26
|
-
You can use Danger to codify your
|
|
26
|
+
You can use Danger to codify your teams norms. Leaving humans to think about harder problems.
|
|
27
27
|
|
|
28
28
|
## For example?
|
|
29
29
|
|
|
@@ -19,7 +19,7 @@ module Danger
|
|
|
19
19
|
# #### GitHub
|
|
20
20
|
#
|
|
21
21
|
# You need to add the `DANGER_GITHUB_API_TOKEN` environment variable, to do this, go to your build definition's variables tab.
|
|
22
|
-
#
|
|
22
|
+
#
|
|
23
23
|
# #### Azure Git
|
|
24
24
|
#
|
|
25
25
|
# You need to add the `DANGER_VSTS_API_TOKEN` and `DANGER_VSTS_HOST` environment variable, to do this,
|
|
@@ -10,10 +10,31 @@ module Danger
|
|
|
10
10
|
#
|
|
11
11
|
# ### Token Setup
|
|
12
12
|
#
|
|
13
|
-
#
|
|
14
|
-
# or instead using `DANGER_BITBUCKETCLOUD_OAUTH_KEY` and `DANGER_BITBUCKETCLOUD_OAUTH_SECRET`.
|
|
13
|
+
# For username and password, you need to set.
|
|
15
14
|
#
|
|
16
|
-
#
|
|
15
|
+
# - `DANGER_BITBUCKETCLOUD_USERNAME` = The username for the account used to comment, as shown on
|
|
16
|
+
# https://bitbucket.org/account/
|
|
17
|
+
# - `DANGER_BITBUCKETCLOUD_PASSWORD` = The password for the account used to comment, you could use
|
|
18
|
+
# [App passwords](https://confluence.atlassian.com/bitbucket/app-passwords-828781300.html#Apppasswords-Aboutapppasswords)
|
|
19
|
+
# with Read Pull Requests and Read Account Permissions.
|
|
20
|
+
#
|
|
21
|
+
# For OAuth key and OAuth secret, you can get them from.
|
|
22
|
+
#
|
|
23
|
+
# - Open [BitBucket Cloud Website](https://bitbucket.org)
|
|
24
|
+
# - Navigate to Settings > OAuth > Add consumer
|
|
25
|
+
# - Put `https://bitbucket.org/site/oauth2/authorize` for `Callback URL`, and enable Read Pull requests, and Read Account
|
|
26
|
+
# Permission.
|
|
27
|
+
#
|
|
28
|
+
# - `DANGER_BITBUCKETCLOUD_OAUTH_KEY` = The consumer key for the account used to comment, as show as `Key` on the website.
|
|
29
|
+
# - `DANGER_BITBUCKETCLOUD_OAUTH_SECRET` = The consumer secret for the account used to comment, as show as `Secret` on the
|
|
30
|
+
# website.
|
|
31
|
+
#
|
|
32
|
+
# For [repository access token](https://support.atlassian.com/bitbucket-cloud/docs/repository-access-tokens/), what you
|
|
33
|
+
# need to create one is:
|
|
34
|
+
#
|
|
35
|
+
# - Open your repository URL
|
|
36
|
+
# - Navigate to Settings > Security > Access Tokens > Create Repository Access Token
|
|
37
|
+
# - Give it a name and set Pull requests write scope
|
|
17
38
|
|
|
18
39
|
class BitbucketPipelines < CI
|
|
19
40
|
def self.validates_as_ci?(env)
|
|
@@ -19,13 +19,13 @@ module Danger
|
|
|
19
19
|
#
|
|
20
20
|
# Add the `DANGER_GITHUB_API_TOKEN` to your workflow's [Secret App Env Vars](https://blog.bitrise.io/anyone-even-prs-can-have-secrets).
|
|
21
21
|
#
|
|
22
|
-
# ###
|
|
22
|
+
# ### Bitbucket Server and Bitrise
|
|
23
23
|
#
|
|
24
|
-
# Danger will read the environment variable GIT_REPOSITORY_URL to construct the Bitbucket Server API URL
|
|
25
|
-
# finding the project and repo slug in the GIT_REPOSITORY_URL variable. This GIT_REPOSITORY_URL variable
|
|
24
|
+
# Danger will read the environment variable `GIT_REPOSITORY_URL` to construct the Bitbucket Server API URL
|
|
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 Bitrise App. If you are manually setting a repo URL in the
|
|
27
27
|
# Git Clone Repo step, you may need to set adjust this property in the settings tab, maybe even fake it.
|
|
28
|
-
# The patterns used are `(%r{\.com/(.*)})` and `(%r{\.com:(.*)})` and
|
|
28
|
+
# The patterns used are `(%r{\.com/(.*)})` and `(%r{\.com:(.*)})` and `.split(/\.git$|$/)` to remove ".git" if the URL contains it.
|
|
29
29
|
#
|
|
30
30
|
class Bitrise < CI
|
|
31
31
|
def self.validates_as_ci?(env)
|
|
@@ -7,7 +7,7 @@ module Danger
|
|
|
7
7
|
# ### CI Setup
|
|
8
8
|
#
|
|
9
9
|
# With BuildKite you run the server yourself, so you will want to run it as a part of your build process.
|
|
10
|
-
# It is common to have build steps, so we would recommend adding this to your
|
|
10
|
+
# It is common to have build steps, so we would recommend adding this to your script:
|
|
11
11
|
#
|
|
12
12
|
# ```shell
|
|
13
13
|
# echo "--- Running Danger"
|
|
@@ -4,8 +4,8 @@ require "danger/request_sources/github/github"
|
|
|
4
4
|
module Danger
|
|
5
5
|
# ### CI Setup
|
|
6
6
|
#
|
|
7
|
-
# In CodeBuild, make sure to correctly forward CODEBUILD_BUILD_ID
|
|
8
|
-
# In CodeBuild with batch builds, make sure to correctly forward CODEBUILD_BUILD_ID
|
|
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`.
|
|
9
9
|
#
|
|
10
10
|
# ### Token Setup
|
|
11
11
|
#
|
data/lib/danger/commands/pr.rb
CHANGED
|
@@ -7,6 +7,8 @@ module Danger
|
|
|
7
7
|
|
|
8
8
|
# Finds a Danger::CI class based on the ENV
|
|
9
9
|
def self.local_ci_source(env)
|
|
10
|
+
return Danger::LocalOnlyGitRepo if LocalOnlyGitRepo.validates_as_ci? env
|
|
11
|
+
|
|
10
12
|
CI.available_ci_sources.find { |ci| ci.validates_as_ci? env }
|
|
11
13
|
end
|
|
12
14
|
|
|
@@ -106,7 +108,7 @@ module Danger
|
|
|
106
108
|
title = "For Danger to run on this project, you need to expose a set of following the ENV vars:\n#{RequestSources::RequestSource.available_source_names_and_envs.join("\n")}"
|
|
107
109
|
end
|
|
108
110
|
|
|
109
|
-
[title,
|
|
111
|
+
[title, subtitle || ""]
|
|
110
112
|
end
|
|
111
113
|
|
|
112
114
|
def ui_display_no_request_source_error_message(ui, env, title, subtitle)
|
|
@@ -237,7 +237,7 @@ module Danger
|
|
|
237
237
|
# @!group GitHub Misc
|
|
238
238
|
# Use to ignore inline messages which lay outside a diff's range, thereby not posting them in the main comment.
|
|
239
239
|
# You can set hash to change behavior per each kinds. (ex. `{warning: true, error: false}`)
|
|
240
|
-
# @param [Bool
|
|
240
|
+
# @param [Bool or Hash<Symbol, Bool>] dismiss
|
|
241
241
|
# Ignore out of range inline messages, defaults to `true`
|
|
242
242
|
#
|
|
243
243
|
# @return [void]
|
|
@@ -248,7 +248,7 @@ module Danger
|
|
|
248
248
|
# @!group Gitlab Misc
|
|
249
249
|
# Use to ignore inline messages which lay outside a diff's range, thereby not posting the comment.
|
|
250
250
|
# You can set hash to change behavior per each kinds. (ex. `{warning: true, error: false}`)
|
|
251
|
-
# @param [Bool
|
|
251
|
+
# @param [Bool or Hash<Symbol, Bool>] dismiss
|
|
252
252
|
# Ignore out of range inline messages, defaults to `true`
|
|
253
253
|
#
|
|
254
254
|
# @return [void]
|
|
@@ -13,12 +13,13 @@ module Danger
|
|
|
13
13
|
# If it's not called again on subsequent runs.
|
|
14
14
|
#
|
|
15
15
|
# Each of `message`, `warn`, `fail` and `markdown` support multiple passed arguments
|
|
16
|
-
# @example
|
|
17
16
|
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
17
|
+
# @example Multiple passed arguments
|
|
18
|
+
#
|
|
19
|
+
# message 'Hello', 'World', file: "Dangerfile", line: 1
|
|
20
|
+
# warn ['This', 'is', 'warning'], file: "Dangerfile", line: 1
|
|
21
|
+
# failure 'Ooops', 'bad bad error', sticky: false
|
|
22
|
+
# markdown '# And', '# Even', '# Markdown', file: "Dangerfile", line: 1
|
|
22
23
|
#
|
|
23
24
|
# By default, using `failure` would fail the corresponding build. Either via an API call, or
|
|
24
25
|
# via the return value for the danger command. Older code examples use `fail` which is an alias
|
|
@@ -87,11 +88,12 @@ module Danger
|
|
|
87
88
|
# @!group Core
|
|
88
89
|
# Print markdown to below the table
|
|
89
90
|
#
|
|
90
|
-
# @param [
|
|
91
|
+
# @param [Hash] options
|
|
92
|
+
# @option [String, Array<String>] markdowns
|
|
91
93
|
# The markdown based message to be printed below the table
|
|
92
|
-
# @
|
|
94
|
+
# @option [String] file
|
|
93
95
|
# Optional. Path to the file that the message is for.
|
|
94
|
-
# @
|
|
96
|
+
# @option [String] line
|
|
95
97
|
# Optional. The line in the file to present the message in.
|
|
96
98
|
# @return [void]
|
|
97
99
|
#
|
|
@@ -107,14 +109,15 @@ module Danger
|
|
|
107
109
|
# @!group Core
|
|
108
110
|
# Print out a generate message on the PR
|
|
109
111
|
#
|
|
110
|
-
# @param [String, Array<String>]
|
|
112
|
+
# @param [String, Array<String>] messages
|
|
111
113
|
# The message to present to the user
|
|
112
|
-
# @param [
|
|
114
|
+
# @param [Hash] options
|
|
115
|
+
# @option [Boolean] sticky
|
|
113
116
|
# Whether the message should be kept after it was fixed,
|
|
114
117
|
# defaults to `false`.
|
|
115
|
-
# @
|
|
118
|
+
# @option [String] file
|
|
116
119
|
# Optional. Path to the file that the message is for.
|
|
117
|
-
# @
|
|
120
|
+
# @option [String] line
|
|
118
121
|
# Optional. The line in the file to present the message in.
|
|
119
122
|
# @return [void]
|
|
120
123
|
#
|
|
@@ -131,14 +134,15 @@ module Danger
|
|
|
131
134
|
# @!group Core
|
|
132
135
|
# Specifies a problem, but not critical
|
|
133
136
|
#
|
|
134
|
-
# @param [String, Array<String>]
|
|
137
|
+
# @param [String, Array<String>] warnings
|
|
135
138
|
# The message to present to the user
|
|
136
|
-
# @param
|
|
139
|
+
# @param options
|
|
140
|
+
# @option [Boolean] sticky
|
|
137
141
|
# Whether the message should be kept after it was fixed,
|
|
138
142
|
# defaults to `false`.
|
|
139
|
-
# @
|
|
143
|
+
# @option [String] file
|
|
140
144
|
# Optional. Path to the file that the message is for.
|
|
141
|
-
# @
|
|
145
|
+
# @option [String] line
|
|
142
146
|
# Optional. The line in the file to present the message in.
|
|
143
147
|
# @return [void]
|
|
144
148
|
#
|
|
@@ -157,14 +161,15 @@ module Danger
|
|
|
157
161
|
# @!group Core
|
|
158
162
|
# Declares a CI blocking error
|
|
159
163
|
#
|
|
160
|
-
# @param [String, Array<String>]
|
|
164
|
+
# @param [String, Array<String>] failures
|
|
161
165
|
# The message to present to the user
|
|
162
|
-
# @param
|
|
166
|
+
# @param options
|
|
167
|
+
# @option [Boolean] sticky
|
|
163
168
|
# Whether the message should be kept after it was fixed,
|
|
164
169
|
# defaults to `false`.
|
|
165
|
-
# @
|
|
170
|
+
# @option [String] file
|
|
166
171
|
# Optional. Path to the file that the message is for.
|
|
167
|
-
# @
|
|
172
|
+
# @option [String] line
|
|
168
173
|
# Optional. The line in the file to present the message in.
|
|
169
174
|
# @return [void]
|
|
170
175
|
#
|
|
@@ -14,14 +14,14 @@ module Danger
|
|
|
14
14
|
Kramdown::Document.new(text, input: "GFM", smart_quotes: %w(apos apos quot quot))
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
#
|
|
17
|
+
# @!group Extension points
|
|
18
18
|
# Produces a markdown link to the file the message points to
|
|
19
19
|
#
|
|
20
20
|
# request_source implementations are invited to override this method with their
|
|
21
21
|
# vendor specific link.
|
|
22
22
|
#
|
|
23
23
|
# @param [Violation or Markdown] message
|
|
24
|
-
# @param [Bool] Should hide any generated link created
|
|
24
|
+
# @param [Bool] hide_link Should hide any generated link created
|
|
25
25
|
#
|
|
26
26
|
# @return [String] The Markdown compatible link
|
|
27
27
|
def markdown_link_to_message(message, hide_link)
|
|
@@ -30,12 +30,12 @@ module Danger
|
|
|
30
30
|
"#{message.file}#L#{message.line}"
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
#
|
|
33
|
+
# @!group Extension points
|
|
34
34
|
# Determine whether two messages are equivalent
|
|
35
35
|
#
|
|
36
36
|
# request_source implementations are invited to override this method.
|
|
37
37
|
# This is mostly here to enable sources to detect when inlines change only in their
|
|
38
|
-
# commit hash and not in content per-se. since the link is implementation
|
|
38
|
+
# commit hash and not in content per-se. since the link is implementation dependent
|
|
39
39
|
# so should be the comparison.
|
|
40
40
|
#
|
|
41
41
|
# @param [Violation or Markdown] m1
|
|
@@ -46,6 +46,8 @@ module Danger
|
|
|
46
46
|
m1 == m2
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
# @endgroup
|
|
50
|
+
|
|
49
51
|
def process_markdown(violation, hide_link = false)
|
|
50
52
|
message = violation.message
|
|
51
53
|
message = "#{markdown_link_to_message(violation, hide_link)}#{message}" if violation.file && violation.line
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Danger
|
|
2
2
|
module Helpers
|
|
3
3
|
module CommentsParsingHelper
|
|
4
|
-
#
|
|
4
|
+
# @!group Extension points
|
|
5
5
|
# Produces a message-like from a row in a comment table
|
|
6
6
|
#
|
|
7
7
|
# @param [String] row
|
|
@@ -12,6 +12,8 @@ module Danger
|
|
|
12
12
|
Violation.new(row, true)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
# @endgroup
|
|
16
|
+
|
|
15
17
|
def parse_tables_from_comment(comment)
|
|
16
18
|
comment.split("</table>")
|
|
17
19
|
end
|
|
@@ -9,17 +9,24 @@ module Danger
|
|
|
9
9
|
attr_accessor :pr_json
|
|
10
10
|
|
|
11
11
|
def self.env_vars
|
|
12
|
+
["DANGER_BITBUCKETCLOUD_UUID"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# While it says "optional", one of these is required to run Danger on Bitbucket Cloud.
|
|
16
|
+
#
|
|
17
|
+
# - Both `DANGER_BITBUCKETCLOUD_OAUTH_KEY` and `DANGER_BITBUCKETCLOUD_OAUTH_SECRET`
|
|
18
|
+
# - Both `DANGER_BITBUCKETCLOUD_USERNAME` and `DANGER_BITBUCKETCLOUD_PASSWORD`
|
|
19
|
+
# - `DANGER_BITBUCKETCLOUD_REPO_ACCESSTOKEN`
|
|
20
|
+
def self.optional_env_vars
|
|
12
21
|
[
|
|
22
|
+
"DANGER_BITBUCKETCLOUD_OAUTH_KEY",
|
|
23
|
+
"DANGER_BITBUCKETCLOUD_OAUTH_SECRET",
|
|
24
|
+
"DANGER_BITBUCKETCLOUD_REPO_ACCESSTOKEN",
|
|
13
25
|
"DANGER_BITBUCKETCLOUD_USERNAME",
|
|
14
|
-
"DANGER_BITBUCKETCLOUD_UUID",
|
|
15
26
|
"DANGER_BITBUCKETCLOUD_PASSWORD"
|
|
16
27
|
]
|
|
17
28
|
end
|
|
18
29
|
|
|
19
|
-
def self.optional_env_vars
|
|
20
|
-
["DANGER_BITBUCKETCLOUD_OAUTH_KEY", "DANGER_BITBUCKETCLOUD_OAUTH_SECRET"]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
30
|
def initialize(ci_source, environment)
|
|
24
31
|
self.ci_source = ci_source
|
|
25
32
|
|
|
@@ -75,7 +82,7 @@ module Danger
|
|
|
75
82
|
messages = update_inline_comments_for_kind!(:messages, messages, danger_id: danger_id)
|
|
76
83
|
markdowns = update_inline_comments_for_kind!(:markdowns, markdowns, danger_id: danger_id)
|
|
77
84
|
|
|
78
|
-
has_comments =
|
|
85
|
+
has_comments = warnings.count.positive? || errors.count.positive? || messages.count.positive? || markdowns.count.positive?
|
|
79
86
|
if has_comments
|
|
80
87
|
comment = generate_description(warnings: warnings, errors: errors, template: "bitbucket_server")
|
|
81
88
|
comment += "\n\n"
|
|
@@ -39,6 +39,8 @@ module Danger
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def credentials_given?
|
|
42
|
+
return true if @access_token
|
|
43
|
+
|
|
42
44
|
@my_uuid && !@my_uuid.empty? &&
|
|
43
45
|
@username && !@username.empty? &&
|
|
44
46
|
@password && !@password.empty?
|
|
@@ -105,6 +107,12 @@ module Danger
|
|
|
105
107
|
end
|
|
106
108
|
|
|
107
109
|
def fetch_access_token(environment)
|
|
110
|
+
access_token = environment["DANGER_BITBUCKETCLOUD_REPO_ACCESSTOKEN"]
|
|
111
|
+
if access_token
|
|
112
|
+
@access_token = access_token
|
|
113
|
+
return access_token
|
|
114
|
+
end
|
|
115
|
+
|
|
108
116
|
oauth_key = environment["DANGER_BITBUCKETCLOUD_OAUTH_KEY"]
|
|
109
117
|
oauth_secret = environment["DANGER_BITBUCKETCLOUD_OAUTH_SECRET"]
|
|
110
118
|
return nil if oauth_key.nil?
|
|
@@ -115,7 +115,7 @@ module Danger
|
|
|
115
115
|
markdowns = main_violations[:markdowns] || []
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
-
has_comments =
|
|
118
|
+
has_comments = warnings.count > 0 || errors.count > 0 || messages.count > 0 || markdowns.count > 0
|
|
119
119
|
if has_comments
|
|
120
120
|
comment = generate_description(warnings: warnings,
|
|
121
121
|
errors: errors)
|
|
@@ -77,7 +77,24 @@ module Danger
|
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def pr_diff
|
|
80
|
-
|
|
80
|
+
# This is a hack to get the file patch into a format that parse-diff accepts
|
|
81
|
+
# as the GitHub API for listing pull request files is missing file names in the patch.
|
|
82
|
+
prefixed_patch = lambda do |file:|
|
|
83
|
+
<<~PATCH
|
|
84
|
+
diff --git a/#{file['filename']} b/#{file['filename']}
|
|
85
|
+
--- a/#{file['filename']}
|
|
86
|
+
+++ b/#{file['filename']}
|
|
87
|
+
#{file['patch']}
|
|
88
|
+
PATCH
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
files = client.pull_request_files(
|
|
92
|
+
ci_source.repo_slug,
|
|
93
|
+
ci_source.pull_request_id,
|
|
94
|
+
accept: "application/vnd.github.v3.diff"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
@pr_diff ||= files.map { |file| prefixed_patch.call(file: file) }.join("\n")
|
|
81
98
|
end
|
|
82
99
|
|
|
83
100
|
def review
|
|
@@ -252,14 +269,16 @@ module Danger
|
|
|
252
269
|
end
|
|
253
270
|
|
|
254
271
|
def submit_inline_comments!(warnings: [], errors: [], messages: [], markdowns: [], previous_violations: [], danger_id: "danger")
|
|
255
|
-
# Avoid doing any fetchs if there's no inline comments
|
|
256
|
-
return {} if (warnings + errors + messages + markdowns).select(&:inline?).empty?
|
|
257
|
-
|
|
258
|
-
diff_lines = self.pr_diff.lines
|
|
259
272
|
pr_comments = client.pull_request_comments(ci_source.repo_slug, ci_source.pull_request_id)
|
|
260
273
|
danger_comments = pr_comments.select { |comment| Comment.from_github(comment).generated_by_danger?(danger_id) }
|
|
261
274
|
non_danger_comments = pr_comments - danger_comments
|
|
262
275
|
|
|
276
|
+
if (warnings + errors + messages + markdowns).select(&:inline?).empty?
|
|
277
|
+
delete_old_inline_violations(danger_comments: danger_comments, non_danger_comments: non_danger_comments)
|
|
278
|
+
return {}
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
diff_lines = self.pr_diff.lines
|
|
263
282
|
warnings = submit_inline_comments_for_kind!(:warning, warnings, diff_lines, danger_comments, previous_violations["warning"], danger_id: danger_id)
|
|
264
283
|
errors = submit_inline_comments_for_kind!(:error, errors, diff_lines, danger_comments, previous_violations["error"], danger_id: danger_id)
|
|
265
284
|
messages = submit_inline_comments_for_kind!(:message, messages, diff_lines, danger_comments, previous_violations["message"], danger_id: danger_id)
|
|
@@ -267,6 +286,17 @@ module Danger
|
|
|
267
286
|
|
|
268
287
|
# submit removes from the array all comments that are still in force
|
|
269
288
|
# so we strike out all remaining ones
|
|
289
|
+
delete_old_inline_violations(danger_comments: danger_comments, non_danger_comments: non_danger_comments)
|
|
290
|
+
|
|
291
|
+
{
|
|
292
|
+
warnings: warnings,
|
|
293
|
+
errors: errors,
|
|
294
|
+
messages: messages,
|
|
295
|
+
markdowns: markdowns
|
|
296
|
+
}
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
def delete_old_inline_violations(danger_comments: [], non_danger_comments: [])
|
|
270
300
|
danger_comments.each do |comment|
|
|
271
301
|
violation = violations_from_table(comment["body"]).first
|
|
272
302
|
if !violation.nil? && violation.sticky
|
|
@@ -285,13 +315,6 @@ module Danger
|
|
|
285
315
|
client.delete_pull_request_comment(ci_source.repo_slug, comment["id"]) if replies.empty?
|
|
286
316
|
end
|
|
287
317
|
end
|
|
288
|
-
|
|
289
|
-
{
|
|
290
|
-
warnings: warnings,
|
|
291
|
-
errors: errors,
|
|
292
|
-
messages: messages,
|
|
293
|
-
markdowns: markdowns
|
|
294
|
-
}
|
|
295
318
|
end
|
|
296
319
|
|
|
297
320
|
def messages_are_equivalent(m1, m2)
|
|
@@ -306,7 +329,7 @@ module Danger
|
|
|
306
329
|
is_markdown_content = kind == :markdown
|
|
307
330
|
emoji = { warning: "warning", error: "no_entry_sign", message: "book" }[kind]
|
|
308
331
|
|
|
309
|
-
messages.reject do |m|
|
|
332
|
+
messages.reject do |m| # rubocop:todo Metrics/BlockLength
|
|
310
333
|
next false unless m.file && m.line
|
|
311
334
|
|
|
312
335
|
position = find_position_in_diff diff_lines, m, kind
|
|
@@ -343,8 +366,10 @@ module Danger
|
|
|
343
366
|
|
|
344
367
|
if matching_comments.empty?
|
|
345
368
|
begin
|
|
369
|
+
# Since Octokit v8, the signature of create_pull_request_comment has been changed.
|
|
370
|
+
# See https://github.com/danger/danger/issues/1475 for detailed information.
|
|
346
371
|
client.create_pull_request_comment(ci_source.repo_slug, ci_source.pull_request_id,
|
|
347
|
-
body, head_ref, m.file, position)
|
|
372
|
+
body, head_ref, m.file, (Octokit::MAJOR >= 8 ? m.line : position))
|
|
348
373
|
rescue Octokit::UnprocessableEntity => e
|
|
349
374
|
# Show more detail for UnprocessableEntity error
|
|
350
375
|
message = [e, "body: #{body}", "head_ref: #{head_ref}", "filename: #{m.file}", "position: #{position}"].join("\n")
|
|
@@ -304,7 +304,7 @@ module Danger
|
|
|
304
304
|
|
|
305
305
|
# @return [String] A URL to the specific file, ready to be downloaded
|
|
306
306
|
def file_url(organisation: nil, repository: nil, ref: nil, branch: nil, path: nil)
|
|
307
|
-
ref ||=
|
|
307
|
+
ref ||= branch || "master"
|
|
308
308
|
# According to GitLab Repositories API docs path and id(slug) should be encoded.
|
|
309
309
|
path = URI.encode_www_form_component(path)
|
|
310
310
|
repository = URI.encode_www_form_component(repository)
|
|
@@ -395,7 +395,7 @@ module Danger
|
|
|
395
395
|
is_markdown_content = kind == :markdown
|
|
396
396
|
emoji = { warning: "warning", error: "no_entry_sign", message: "book" }[kind]
|
|
397
397
|
|
|
398
|
-
messages.reject do |m|
|
|
398
|
+
messages.reject do |m| # rubocop:todo Metrics/BlockLength
|
|
399
399
|
next false unless m.file && m.line
|
|
400
400
|
# Reject if it's out of range and in dismiss mode
|
|
401
401
|
next true if dismiss_out_of_range_messages_for(kind) && is_out_of_range(mr_changes.changes, m)
|
|
@@ -139,7 +139,7 @@ module Danger
|
|
|
139
139
|
end
|
|
140
140
|
|
|
141
141
|
def submit_inline_comments!(warnings: [], errors: [], messages: [], markdowns: [], previous_violations: [], danger_id: "danger")
|
|
142
|
-
# Avoid doing any
|
|
142
|
+
# Avoid doing any fetches if there's no inline comments
|
|
143
143
|
return {} if (warnings + errors + messages + markdowns).select(&:inline?).empty?
|
|
144
144
|
|
|
145
145
|
pr_threads = @api.fetch_last_comments
|
|
@@ -185,7 +185,7 @@ module Danger
|
|
|
185
185
|
is_markdown_content = kind == :markdown
|
|
186
186
|
emoji = { warning: "warning", error: "no_entry_sign", message: "book" }[kind]
|
|
187
187
|
|
|
188
|
-
messages.reject do |m|
|
|
188
|
+
messages.reject do |m| # rubocop:todo Metrics/BlockLength
|
|
189
189
|
next false unless m.file && m.line
|
|
190
190
|
|
|
191
191
|
# Once we know we're gonna submit it, we format it
|
|
@@ -144,13 +144,16 @@ module Danger
|
|
|
144
144
|
return unless from_is_ref || to_is_ref
|
|
145
145
|
|
|
146
146
|
depth = 0
|
|
147
|
-
(3..6).
|
|
147
|
+
(3..6).each do |factor|
|
|
148
148
|
depth += Math.exp(factor).to_i
|
|
149
149
|
|
|
150
150
|
git_fetch_branch_to_depth(from, depth) if from_is_ref
|
|
151
151
|
git_fetch_branch_to_depth(to, depth) if to_is_ref
|
|
152
|
-
possible_merge_base(repo, from, to)
|
|
152
|
+
merge_base = possible_merge_base(repo, from, to)
|
|
153
|
+
return merge_base if merge_base
|
|
153
154
|
end
|
|
155
|
+
|
|
156
|
+
nil
|
|
154
157
|
end
|
|
155
158
|
|
|
156
159
|
def possible_merge_base(repo, from, to)
|
data/lib/danger/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: danger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 9.
|
|
4
|
+
version: 9.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Orta Therox
|
|
8
8
|
- Juanito Fatas
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2025-07-04 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: base64
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.2'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.2'
|
|
14
27
|
- !ruby/object:Gem::Dependency
|
|
15
28
|
name: claide
|
|
16
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -43,16 +56,22 @@ dependencies:
|
|
|
43
56
|
name: colored2
|
|
44
57
|
requirement: !ruby/object:Gem::Requirement
|
|
45
58
|
requirements:
|
|
46
|
-
- - "
|
|
59
|
+
- - ">="
|
|
47
60
|
- !ruby/object:Gem::Version
|
|
48
61
|
version: '3.1'
|
|
62
|
+
- - "<"
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '5'
|
|
49
65
|
type: :runtime
|
|
50
66
|
prerelease: false
|
|
51
67
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
68
|
requirements:
|
|
53
|
-
- - "
|
|
69
|
+
- - ">="
|
|
54
70
|
- !ruby/object:Gem::Version
|
|
55
71
|
version: '3.1'
|
|
72
|
+
- - "<"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '5'
|
|
56
75
|
- !ruby/object:Gem::Dependency
|
|
57
76
|
name: cork
|
|
58
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -105,30 +124,42 @@ dependencies:
|
|
|
105
124
|
name: git
|
|
106
125
|
requirement: !ruby/object:Gem::Requirement
|
|
107
126
|
requirements:
|
|
108
|
-
- - "
|
|
127
|
+
- - ">="
|
|
109
128
|
- !ruby/object:Gem::Version
|
|
110
129
|
version: '1.13'
|
|
130
|
+
- - "<"
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '3.0'
|
|
111
133
|
type: :runtime
|
|
112
134
|
prerelease: false
|
|
113
135
|
version_requirements: !ruby/object:Gem::Requirement
|
|
114
136
|
requirements:
|
|
115
|
-
- - "
|
|
137
|
+
- - ">="
|
|
116
138
|
- !ruby/object:Gem::Version
|
|
117
139
|
version: '1.13'
|
|
140
|
+
- - "<"
|
|
141
|
+
- !ruby/object:Gem::Version
|
|
142
|
+
version: '3.0'
|
|
118
143
|
- !ruby/object:Gem::Dependency
|
|
119
144
|
name: kramdown
|
|
120
145
|
requirement: !ruby/object:Gem::Requirement
|
|
121
146
|
requirements:
|
|
122
|
-
- - "
|
|
147
|
+
- - ">="
|
|
148
|
+
- !ruby/object:Gem::Version
|
|
149
|
+
version: 2.5.1
|
|
150
|
+
- - "<"
|
|
123
151
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: '
|
|
152
|
+
version: '3.0'
|
|
125
153
|
type: :runtime
|
|
126
154
|
prerelease: false
|
|
127
155
|
version_requirements: !ruby/object:Gem::Requirement
|
|
128
156
|
requirements:
|
|
129
|
-
- - "
|
|
157
|
+
- - ">="
|
|
130
158
|
- !ruby/object:Gem::Version
|
|
131
|
-
version:
|
|
159
|
+
version: 2.5.1
|
|
160
|
+
- - "<"
|
|
161
|
+
- !ruby/object:Gem::Version
|
|
162
|
+
version: '3.0'
|
|
132
163
|
- !ruby/object:Gem::Dependency
|
|
133
164
|
name: kramdown-parser-gfm
|
|
134
165
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -144,33 +175,33 @@ dependencies:
|
|
|
144
175
|
- !ruby/object:Gem::Version
|
|
145
176
|
version: '1.0'
|
|
146
177
|
- !ruby/object:Gem::Dependency
|
|
147
|
-
name:
|
|
178
|
+
name: octokit
|
|
148
179
|
requirement: !ruby/object:Gem::Requirement
|
|
149
180
|
requirements:
|
|
150
181
|
- - ">="
|
|
151
182
|
- !ruby/object:Gem::Version
|
|
152
|
-
version: '0'
|
|
183
|
+
version: '4.0'
|
|
153
184
|
type: :runtime
|
|
154
185
|
prerelease: false
|
|
155
186
|
version_requirements: !ruby/object:Gem::Requirement
|
|
156
187
|
requirements:
|
|
157
188
|
- - ">="
|
|
158
189
|
- !ruby/object:Gem::Version
|
|
159
|
-
version: '0'
|
|
190
|
+
version: '4.0'
|
|
160
191
|
- !ruby/object:Gem::Dependency
|
|
161
|
-
name:
|
|
192
|
+
name: pstore
|
|
162
193
|
requirement: !ruby/object:Gem::Requirement
|
|
163
194
|
requirements:
|
|
164
|
-
- - "
|
|
195
|
+
- - "~>"
|
|
165
196
|
- !ruby/object:Gem::Version
|
|
166
|
-
version: '
|
|
197
|
+
version: '0.1'
|
|
167
198
|
type: :runtime
|
|
168
199
|
prerelease: false
|
|
169
200
|
version_requirements: !ruby/object:Gem::Requirement
|
|
170
201
|
requirements:
|
|
171
|
-
- - "
|
|
202
|
+
- - "~>"
|
|
172
203
|
- !ruby/object:Gem::Version
|
|
173
|
-
version: '
|
|
204
|
+
version: '0.1'
|
|
174
205
|
- !ruby/object:Gem::Dependency
|
|
175
206
|
name: terminal-table
|
|
176
207
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -180,7 +211,7 @@ dependencies:
|
|
|
180
211
|
version: '1'
|
|
181
212
|
- - "<"
|
|
182
213
|
- !ruby/object:Gem::Version
|
|
183
|
-
version: '
|
|
214
|
+
version: '5'
|
|
184
215
|
type: :runtime
|
|
185
216
|
prerelease: false
|
|
186
217
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -190,7 +221,7 @@ dependencies:
|
|
|
190
221
|
version: '1'
|
|
191
222
|
- - "<"
|
|
192
223
|
- !ruby/object:Gem::Version
|
|
193
|
-
version: '
|
|
224
|
+
version: '5'
|
|
194
225
|
description: Stop Saying 'You Forgot To…' in Code Review
|
|
195
226
|
email:
|
|
196
227
|
- orta.therox@gmail.com
|
|
@@ -329,7 +360,6 @@ homepage: https://github.com/danger/danger
|
|
|
329
360
|
licenses:
|
|
330
361
|
- MIT
|
|
331
362
|
metadata: {}
|
|
332
|
-
post_install_message:
|
|
333
363
|
rdoc_options: []
|
|
334
364
|
require_paths:
|
|
335
365
|
- lib
|
|
@@ -344,8 +374,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
344
374
|
- !ruby/object:Gem::Version
|
|
345
375
|
version: '0'
|
|
346
376
|
requirements: []
|
|
347
|
-
rubygems_version: 3.
|
|
348
|
-
signing_key:
|
|
377
|
+
rubygems_version: 3.6.2
|
|
349
378
|
specification_version: 4
|
|
350
379
|
summary: Like Unit Tests, but for your Team Culture.
|
|
351
380
|
test_files: []
|