danger 9.5.1 → 9.5.2
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/lib/danger/ci_source/local_git_repo.rb +9 -5
- data/lib/danger/ci_source/support/find_repo_info_from_url.rb +3 -1
- data/lib/danger/ci_source/support/pull_request_finder.rb +62 -22
- data/lib/danger/commands/mr.rb +89 -0
- data/lib/danger/commands/runner.rb +1 -0
- data/lib/danger/request_sources/github/github.rb +1 -1
- data/lib/danger/request_sources/gitlab.rb +1 -1
- data/lib/danger/request_sources/vsts.rb +1 -1
- data/lib/danger/version.rb +1 -1
- metadata +32 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17279e83964586e1eef46c40740b9c0fb839ea85a3c3d367a898c9b664767eca
|
4
|
+
data.tar.gz: 6afc0eb2cb97f22d988bf56cb0fe48063aa5eab060471cff2d95c0bc8435b3da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee7544abd31b5bd6320efdc79668169d0c5bfc0aa873b2d971bdfb043ab08bd3e05149ddc714cbcd98257c7bd0c815e4899afd573c33ff5d815626fdf01c1c01
|
7
|
+
data.tar.gz: fbe7c247fee1a41cb6e212141896f7282547f91f8ad0b59f36ae18bab2e32783e1b3ff22db1231e30e6bb5d3feaa98aea67099f114eaa9a45e30dc2478d562b0
|
@@ -38,7 +38,8 @@ module Danger
|
|
38
38
|
Danger::RequestSources::GitHub,
|
39
39
|
Danger::RequestSources::BitbucketServer,
|
40
40
|
Danger::RequestSources::BitbucketCloud,
|
41
|
-
Danger::RequestSources::VSTS
|
41
|
+
Danger::RequestSources::VSTS,
|
42
|
+
Danger::RequestSources::GitLab
|
42
43
|
]
|
43
44
|
end
|
44
45
|
|
@@ -74,7 +75,8 @@ module Danger
|
|
74
75
|
|
75
76
|
def find_remote_info(env)
|
76
77
|
if given_pull_request_url?(env)
|
77
|
-
|
78
|
+
pr_url = env["LOCAL_GIT_PR_URL"] || env["LOCAL_GIT_MR_URL"]
|
79
|
+
FindRepoInfoFromURL.new(pr_url).call
|
78
80
|
else
|
79
81
|
FindRepoInfoFromLogs.new(
|
80
82
|
env["DANGER_GITHUB_HOST"] || "github.com",
|
@@ -85,15 +87,16 @@ module Danger
|
|
85
87
|
|
86
88
|
def find_pull_request(env)
|
87
89
|
if given_pull_request_url?(env)
|
90
|
+
remote_url = env["LOCAL_GIT_PR_URL"] || env["LOCAL_GIT_MR_URL"]
|
88
91
|
PullRequestFinder.new(
|
89
92
|
remote_info.id,
|
90
93
|
remote_info.slug,
|
91
94
|
remote: true,
|
92
|
-
remote_url:
|
95
|
+
remote_url: remote_url
|
93
96
|
).call(env: env)
|
94
97
|
else
|
95
98
|
PullRequestFinder.new(
|
96
|
-
env.fetch("LOCAL_GIT_PR_ID") { "" },
|
99
|
+
env.fetch("LOCAL_GIT_PR_ID") { env.fetch("LOCAL_GIT_MR_ID") { "" } },
|
97
100
|
remote_info.slug,
|
98
101
|
remote: false,
|
99
102
|
git_logs: run_git("log --oneline -1000000")
|
@@ -102,7 +105,8 @@ module Danger
|
|
102
105
|
end
|
103
106
|
|
104
107
|
def given_pull_request_url?(env)
|
105
|
-
env["LOCAL_GIT_PR_URL"] && !env["LOCAL_GIT_PR_URL"].empty?
|
108
|
+
(env["LOCAL_GIT_PR_URL"] && !env["LOCAL_GIT_PR_URL"].empty?) ||
|
109
|
+
(env["LOCAL_GIT_MR_URL"] && !env["LOCAL_GIT_MR_URL"].empty?)
|
106
110
|
end
|
107
111
|
|
108
112
|
def sha
|
@@ -31,7 +31,9 @@ module Danger
|
|
31
31
|
else
|
32
32
|
matched = url.match(REGEXP)
|
33
33
|
if matched
|
34
|
-
|
34
|
+
# Clean up the slug to remove any trailing dashes or slashes that might be part of the GitLab URL format
|
35
|
+
clean_slug = matched[:slug].gsub(%r{[-/]+$}, "")
|
36
|
+
RepoInfo.new(clean_slug, matched[:id])
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -81,6 +81,12 @@ module Danger
|
|
81
81
|
remote_pull_request.head.sha,
|
82
82
|
remote_pull_request.base.sha
|
83
83
|
)
|
84
|
+
when :gitlab
|
85
|
+
RemotePullRequest.new(
|
86
|
+
remote_pull_request.iid.to_s,
|
87
|
+
remote_pull_request.diff_refs.head_sha,
|
88
|
+
remote_pull_request.diff_refs.base_sha
|
89
|
+
)
|
84
90
|
when :vsts
|
85
91
|
RemotePullRequest.new(
|
86
92
|
remote_pull_request[:pullRequestId].to_s,
|
@@ -93,7 +99,13 @@ module Danger
|
|
93
99
|
end
|
94
100
|
|
95
101
|
def find_remote_pull_request(env)
|
96
|
-
|
102
|
+
scm_provider = find_scm_provider(remote_url)
|
103
|
+
|
104
|
+
if scm_provider == :gitlab
|
105
|
+
client(env).merge_request(repo_slug, specific_pull_request_id)
|
106
|
+
else
|
107
|
+
client(env).pull_request(repo_slug, specific_pull_request_id)
|
108
|
+
end
|
97
109
|
end
|
98
110
|
|
99
111
|
def both_present?
|
@@ -138,35 +150,61 @@ module Danger
|
|
138
150
|
|
139
151
|
case scm_provider
|
140
152
|
when :bitbucket_cloud
|
141
|
-
|
142
|
-
branch_name = ENV["DANGER_BITBUCKET_TARGET_BRANCH"] # Optional env variable (specifying the target branch) to help find the PR.
|
143
|
-
RequestSources::BitbucketCloudAPI.new(repo_slug, specific_pull_request_id, branch_name, env)
|
144
|
-
|
153
|
+
bitbucket_cloud_client(env)
|
145
154
|
when :bitbucket_server
|
146
|
-
|
147
|
-
project, slug = repo_slug.split("/")
|
148
|
-
RequestSources::BitbucketServerAPI.new(project, slug, specific_pull_request_id, env)
|
149
|
-
|
155
|
+
bitbucket_server_client(env)
|
150
156
|
when :vsts
|
151
|
-
|
152
|
-
|
153
|
-
|
157
|
+
vsts_client(env)
|
158
|
+
when :gitlab
|
159
|
+
gitlab_client(env)
|
154
160
|
when :github
|
155
|
-
|
156
|
-
access_token = ENV["DANGER_GITHUB_API_TOKEN"]
|
157
|
-
bearer_token = ENV["DANGER_GITHUB_BEARER_TOKEN"]
|
158
|
-
if bearer_token && !bearer_token.empty?
|
159
|
-
Octokit::Client.new(bearer_token: bearer_token, api_endpoint: api_url)
|
160
|
-
elsif access_token && !access_token.empty?
|
161
|
-
Octokit::Client.new(access_token: access_token, api_endpoint: api_url)
|
162
|
-
else
|
163
|
-
raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN` or `DANGER_GITHUB_BEARER_TOKEN`"
|
164
|
-
end
|
161
|
+
github_client(env)
|
165
162
|
else
|
166
163
|
raise "SCM provider not supported: #{scm_provider}"
|
167
164
|
end
|
168
165
|
end
|
169
166
|
|
167
|
+
def bitbucket_cloud_client(env)
|
168
|
+
require "danger/request_sources/bitbucket_cloud_api"
|
169
|
+
branch_name = ENV["DANGER_BITBUCKET_TARGET_BRANCH"] # Optional env variable (specifying the target branch) to help find the PR.
|
170
|
+
RequestSources::BitbucketCloudAPI.new(repo_slug, specific_pull_request_id, branch_name, env)
|
171
|
+
end
|
172
|
+
|
173
|
+
def bitbucket_server_client(env)
|
174
|
+
require "danger/request_sources/bitbucket_server_api"
|
175
|
+
project, slug = repo_slug.split("/")
|
176
|
+
RequestSources::BitbucketServerAPI.new(project, slug, specific_pull_request_id, env)
|
177
|
+
end
|
178
|
+
|
179
|
+
def vsts_client(env)
|
180
|
+
require "danger/request_sources/vsts_api"
|
181
|
+
RequestSources::VSTSAPI.new(repo_slug, specific_pull_request_id, env)
|
182
|
+
end
|
183
|
+
|
184
|
+
def gitlab_client(env)
|
185
|
+
require "gitlab"
|
186
|
+
token = env&.fetch("DANGER_GITLAB_API_TOKEN", nil) || ENV["DANGER_GITLAB_API_TOKEN"]
|
187
|
+
if token && !token.empty?
|
188
|
+
endpoint = env&.fetch("DANGER_GITLAB_API_BASE_URL", nil) || env&.fetch("CI_API_V4_URL", nil) || ENV["DANGER_GITLAB_API_BASE_URL"] || ENV.fetch("CI_API_V4_URL", "https://gitlab.com/api/v4")
|
189
|
+
Gitlab.client(endpoint: endpoint, private_token: token)
|
190
|
+
else
|
191
|
+
raise "No API token given, please provide one using `DANGER_GITLAB_API_TOKEN`"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def github_client(env)
|
196
|
+
require "octokit"
|
197
|
+
access_token = env&.fetch("DANGER_GITHUB_API_TOKEN", nil) || ENV["DANGER_GITHUB_API_TOKEN"]
|
198
|
+
bearer_token = env&.fetch("DANGER_GITHUB_BEARER_TOKEN", nil) || ENV["DANGER_GITHUB_BEARER_TOKEN"]
|
199
|
+
if bearer_token && !bearer_token.empty?
|
200
|
+
Octokit::Client.new(bearer_token: bearer_token, api_endpoint: api_url)
|
201
|
+
elsif access_token && !access_token.empty?
|
202
|
+
Octokit::Client.new(access_token: access_token, api_endpoint: api_url)
|
203
|
+
else
|
204
|
+
raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN` or `DANGER_GITHUB_BEARER_TOKEN`"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
170
208
|
def api_url
|
171
209
|
ENV.fetch("DANGER_GITHUB_API_HOST") do
|
172
210
|
ENV.fetch("DANGER_GITHUB_API_BASE_URL") do
|
@@ -182,6 +220,8 @@ module Danger
|
|
182
220
|
:bitbucket_server
|
183
221
|
elsif remote_url =~ /\.visualstudio\.com/i || remote_url =~ /dev\.azure\.com/i
|
184
222
|
:vsts
|
223
|
+
elsif remote_url =~ /gitlab\.com/ || remote_url =~ %r{-/merge_requests/}
|
224
|
+
:gitlab
|
185
225
|
else
|
186
226
|
:github
|
187
227
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "danger/commands/local_helpers/http_cache"
|
4
|
+
require "danger/commands/local_helpers/pry_setup"
|
5
|
+
require "faraday/http_cache"
|
6
|
+
require "fileutils"
|
7
|
+
require "gitlab"
|
8
|
+
require "tmpdir"
|
9
|
+
|
10
|
+
module Danger
|
11
|
+
class MR < Runner
|
12
|
+
self.summary = "Run the Dangerfile locally against GitLab Merge Requests. Does not post to the MR. Usage: danger mr <URL>"
|
13
|
+
self.command = "mr"
|
14
|
+
|
15
|
+
def self.options
|
16
|
+
[
|
17
|
+
["--clear-http-cache", "Clear the local http cache before running Danger locally."],
|
18
|
+
["--pry", "Drop into a Pry shell after evaluating the Dangerfile."],
|
19
|
+
["--dangerfile=<path/to/dangerfile>", "The location of your Dangerfile"]
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(argv)
|
24
|
+
show_help = true if argv.arguments == ["-h"]
|
25
|
+
|
26
|
+
@mr_url = argv.shift_argument
|
27
|
+
@clear_http_cache = argv.flag?("clear-http-cache", false)
|
28
|
+
dangerfile = argv.option("dangerfile", "Dangerfile")
|
29
|
+
|
30
|
+
# Currently CLAide doesn't support short option like -h https://github.com/CocoaPods/CLAide/pull/60
|
31
|
+
# when user pass in -h, mimic the behavior of passing in --help.
|
32
|
+
argv = CLAide::ARGV.new ["--help"] if show_help
|
33
|
+
|
34
|
+
super
|
35
|
+
|
36
|
+
@dangerfile_path = dangerfile if File.exist?(dangerfile)
|
37
|
+
|
38
|
+
if argv.flag?("pry", false)
|
39
|
+
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path, MR.command)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate!
|
44
|
+
super
|
45
|
+
unless @dangerfile_path
|
46
|
+
help! "Could not find a Dangerfile."
|
47
|
+
end
|
48
|
+
unless @mr_url
|
49
|
+
help! "Could not find a merge-request. Usage: danger mr <URL>"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def run
|
54
|
+
ENV["DANGER_USE_LOCAL_GIT"] = "YES"
|
55
|
+
ENV["LOCAL_GIT_MR_URL"] = @mr_url if @mr_url
|
56
|
+
|
57
|
+
configure_gitlab(ENV["DANGER_TMPDIR"] || Dir.tmpdir)
|
58
|
+
|
59
|
+
env = EnvironmentManager.new(ENV, cork)
|
60
|
+
dm = Dangerfile.new(env, cork)
|
61
|
+
|
62
|
+
LocalSetup.new(dm, cork).setup(verbose: verbose) do
|
63
|
+
dm.run(
|
64
|
+
Danger::EnvironmentManager.danger_base_branch,
|
65
|
+
Danger::EnvironmentManager.danger_head_branch,
|
66
|
+
@dangerfile_path,
|
67
|
+
nil,
|
68
|
+
nil,
|
69
|
+
nil,
|
70
|
+
false
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def configure_gitlab(cache_dir)
|
78
|
+
# setup caching for GitLab calls to avoid hitting the API rate limit too quickly
|
79
|
+
cache_file = File.join(cache_dir, "danger_local_gitlab_cache")
|
80
|
+
HTTPCache.new(cache_file, clear_cache: @clear_http_cache)
|
81
|
+
|
82
|
+
# Configure GitLab client
|
83
|
+
Gitlab.configure do |config|
|
84
|
+
config.endpoint = ENV["DANGER_GITLAB_API_BASE_URL"] || ENV.fetch("CI_API_V4_URL", "https://gitlab.com/api/v4")
|
85
|
+
config.private_token = ENV["DANGER_GITLAB_API_TOKEN"]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -329,7 +329,7 @@ module Danger
|
|
329
329
|
is_markdown_content = kind == :markdown
|
330
330
|
emoji = { warning: "warning", error: "no_entry_sign", message: "book" }[kind]
|
331
331
|
|
332
|
-
messages.reject do |m|
|
332
|
+
messages.reject do |m| # rubocop:todo Metrics/BlockLength
|
333
333
|
next false unless m.file && m.line
|
334
334
|
|
335
335
|
position = find_position_in_diff diff_lines, m, kind
|
@@ -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)
|
@@ -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
|
data/lib/danger/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.5.
|
4
|
+
version: 9.5.2
|
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-03 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: base64
|
@@ -57,16 +56,22 @@ dependencies:
|
|
57
56
|
name: colored2
|
58
57
|
requirement: !ruby/object:Gem::Requirement
|
59
58
|
requirements:
|
60
|
-
- - "
|
59
|
+
- - ">="
|
61
60
|
- !ruby/object:Gem::Version
|
62
61
|
version: '3.1'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '5'
|
63
65
|
type: :runtime
|
64
66
|
prerelease: false
|
65
67
|
version_requirements: !ruby/object:Gem::Requirement
|
66
68
|
requirements:
|
67
|
-
- - "
|
69
|
+
- - ">="
|
68
70
|
- !ruby/object:Gem::Version
|
69
71
|
version: '3.1'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5'
|
70
75
|
- !ruby/object:Gem::Dependency
|
71
76
|
name: cork
|
72
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,30 +124,42 @@ dependencies:
|
|
119
124
|
name: git
|
120
125
|
requirement: !ruby/object:Gem::Requirement
|
121
126
|
requirements:
|
122
|
-
- - "
|
127
|
+
- - ">="
|
123
128
|
- !ruby/object:Gem::Version
|
124
129
|
version: '1.13'
|
130
|
+
- - "<"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '3.0'
|
125
133
|
type: :runtime
|
126
134
|
prerelease: false
|
127
135
|
version_requirements: !ruby/object:Gem::Requirement
|
128
136
|
requirements:
|
129
|
-
- - "
|
137
|
+
- - ">="
|
130
138
|
- !ruby/object:Gem::Version
|
131
139
|
version: '1.13'
|
140
|
+
- - "<"
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '3.0'
|
132
143
|
- !ruby/object:Gem::Dependency
|
133
144
|
name: kramdown
|
134
145
|
requirement: !ruby/object:Gem::Requirement
|
135
146
|
requirements:
|
136
|
-
- - "
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 2.5.1
|
150
|
+
- - "<"
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '3.0'
|
139
153
|
type: :runtime
|
140
154
|
prerelease: false
|
141
155
|
version_requirements: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
|
-
- - "
|
157
|
+
- - ">="
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
159
|
+
version: 2.5.1
|
160
|
+
- - "<"
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '3.0'
|
146
163
|
- !ruby/object:Gem::Dependency
|
147
164
|
name: kramdown-parser-gfm
|
148
165
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,7 +211,7 @@ dependencies:
|
|
194
211
|
version: '1'
|
195
212
|
- - "<"
|
196
213
|
- !ruby/object:Gem::Version
|
197
|
-
version: '
|
214
|
+
version: '5'
|
198
215
|
type: :runtime
|
199
216
|
prerelease: false
|
200
217
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -204,7 +221,7 @@ dependencies:
|
|
204
221
|
version: '1'
|
205
222
|
- - "<"
|
206
223
|
- !ruby/object:Gem::Version
|
207
|
-
version: '
|
224
|
+
version: '5'
|
208
225
|
description: Stop Saying 'You Forgot To…' in Code Review
|
209
226
|
email:
|
210
227
|
- orta.therox@gmail.com
|
@@ -271,6 +288,7 @@ files:
|
|
271
288
|
- lib/danger/commands/local_helpers/http_cache.rb
|
272
289
|
- lib/danger/commands/local_helpers/local_setup.rb
|
273
290
|
- lib/danger/commands/local_helpers/pry_setup.rb
|
291
|
+
- lib/danger/commands/mr.rb
|
274
292
|
- lib/danger/commands/plugins/plugin_json.rb
|
275
293
|
- lib/danger/commands/plugins/plugin_lint.rb
|
276
294
|
- lib/danger/commands/plugins/plugin_readme.rb
|
@@ -343,7 +361,6 @@ homepage: https://github.com/danger/danger
|
|
343
361
|
licenses:
|
344
362
|
- MIT
|
345
363
|
metadata: {}
|
346
|
-
post_install_message:
|
347
364
|
rdoc_options: []
|
348
365
|
require_paths:
|
349
366
|
- lib
|
@@ -358,8 +375,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
358
375
|
- !ruby/object:Gem::Version
|
359
376
|
version: '0'
|
360
377
|
requirements: []
|
361
|
-
rubygems_version: 3.
|
362
|
-
signing_key:
|
378
|
+
rubygems_version: 3.6.2
|
363
379
|
specification_version: 4
|
364
380
|
summary: Like Unit Tests, but for your Team Culture.
|
365
381
|
test_files: []
|