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
data/lib/danger/commands/init.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/commands/init_helpers/interviewer"
|
|
2
4
|
require "danger/danger_core/dangerfile_generator"
|
|
3
5
|
require "danger/ci_source/local_git_repo"
|
|
@@ -18,7 +20,7 @@ module Danger
|
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def initialize(argv)
|
|
21
|
-
@bot_name = File.basename(Dir.getwd).split(
|
|
23
|
+
@bot_name = "#{File.basename(Dir.getwd).split('.').first.capitalize}Bot"
|
|
22
24
|
super
|
|
23
25
|
@ui = Interviewer.new(cork)
|
|
24
26
|
ui.no_delay = argv.flag?("impatient", false)
|
|
@@ -63,7 +65,7 @@ module Danger
|
|
|
63
65
|
|
|
64
66
|
ui.say "cat #{Dir.pwd}/Dangerfile\n".blue
|
|
65
67
|
content.lines.each do |l|
|
|
66
|
-
ui.say "
|
|
68
|
+
ui.say " #{l.chomp.green}"
|
|
67
69
|
end
|
|
68
70
|
ui.say ""
|
|
69
71
|
ui.pause 2
|
|
@@ -118,7 +120,7 @@ module Danger
|
|
|
118
120
|
|
|
119
121
|
if considered_an_oss_repo?
|
|
120
122
|
ui.say "For Open Source projects, I'd recommend giving the token the smallest scope possible."
|
|
121
|
-
ui.say "This means only providing access to
|
|
123
|
+
ui.say "This means only providing access to #{'public_repo'.yellow} in the token.\n\n"
|
|
122
124
|
ui.pause 1
|
|
123
125
|
ui.say "This token limits Danger's abilities to just writing comments on OSS projects. I recommend"
|
|
124
126
|
ui.say "this because the token can quite easily be extracted from the environment via pull requests."
|
|
@@ -126,10 +128,10 @@ module Danger
|
|
|
126
128
|
ui.say "\nIt is important that you do not store this token in your repository, as GitHub will automatically revoke it when pushed.\n"
|
|
127
129
|
elsif @is_open_source == "closed"
|
|
128
130
|
ui.say "For Closed Source projects, I'd recommend giving the token access to the whole repo scope."
|
|
129
|
-
ui.say "This means only providing access to
|
|
131
|
+
ui.say "This means only providing access to #{'repo'.yellow}, and its children in the token.\n\n"
|
|
130
132
|
ui.pause 1
|
|
131
|
-
ui.say "It's worth noting that you
|
|
132
|
-
ui.say "Make a new one for those repos with just
|
|
133
|
+
ui.say "It's worth noting that you #{'should not'.bold.white} re-use this token for OSS repos."
|
|
134
|
+
ui.say "Make a new one for those repos with just #{'public_repo'.yellow}."
|
|
133
135
|
ui.pause 1
|
|
134
136
|
ui.say "Additionally, don't forget to add your new GitHub account as a collaborator to your Closed Source project."
|
|
135
137
|
end
|
|
@@ -184,13 +186,13 @@ module Danger
|
|
|
184
186
|
danger = "bundle exec danger".yellow
|
|
185
187
|
config = YAML.load(File.read(".travis.yml"))
|
|
186
188
|
if config.kind_of?(Hash) && config["script"]
|
|
187
|
-
ui.say "Add
|
|
189
|
+
ui.say "Add #{'- '.yellow}#{danger} as a new step in the #{'script'.yellow} section of your .travis.yml file."
|
|
188
190
|
else
|
|
189
|
-
ui.say "I'd recommend adding
|
|
191
|
+
ui.say "I'd recommend adding #{'before_script: '.yellow}#{danger} to the script section of your .travis.yml file."
|
|
190
192
|
end
|
|
191
193
|
|
|
192
194
|
ui.pause 1
|
|
193
|
-
ui.say "You shouldn't use
|
|
195
|
+
ui.say "You shouldn't use #{'after_success, after_failure, after_script'.red} as they cannot fail your builds."
|
|
194
196
|
end
|
|
195
197
|
|
|
196
198
|
def uses_circle
|
|
@@ -199,9 +201,9 @@ module Danger
|
|
|
199
201
|
|
|
200
202
|
if config.kind_of?(Hash) && config["test"]
|
|
201
203
|
if config["test"]["post"]
|
|
202
|
-
ui.say "Add
|
|
204
|
+
ui.say "Add #{danger} as a new step in the #{'test:post:'.yellow} section of your circle.yml file."
|
|
203
205
|
else
|
|
204
|
-
ui.say "Add
|
|
206
|
+
ui.say "Add #{danger} as a new step in the #{'test:override:'.yellow} section of your circle.yml file."
|
|
205
207
|
end
|
|
206
208
|
else
|
|
207
209
|
ui.say "Add this to the bottom of your circle.yml file:"
|
|
@@ -214,7 +216,7 @@ module Danger
|
|
|
214
216
|
def unsure_ci
|
|
215
217
|
danger = "bundle exec danger".yellow
|
|
216
218
|
ui.say "As I'm not sure what CI you want to run Danger on based on the files in your repo, I'll just offer some generic"
|
|
217
|
-
ui.say "advice. You want to run
|
|
219
|
+
ui.say "advice. You want to run #{danger} after your tests have finished running, it should still be during the testing"
|
|
218
220
|
ui.say "process so the build can fail."
|
|
219
221
|
end
|
|
220
222
|
|
|
@@ -222,7 +224,7 @@ module Danger
|
|
|
222
224
|
# https://travis-ci.org/artsy/eigen/settings
|
|
223
225
|
ui.say "In order to add an environment variable, go to:"
|
|
224
226
|
ui.link "https://travis-ci.org/#{current_repo_slug}/settings"
|
|
225
|
-
ui.say "\nThe name is
|
|
227
|
+
ui.say "\nThe name is #{'DANGER_GITHUB_API_TOKEN'.yellow} and the value is the GitHub Personal Access Token."
|
|
226
228
|
if @is_open_source
|
|
227
229
|
ui.say 'Make sure to have "Display value in build log" enabled.'
|
|
228
230
|
end
|
|
@@ -239,7 +241,7 @@ module Danger
|
|
|
239
241
|
ui.say "I'll give you a minute to read it..."
|
|
240
242
|
ui.wait_for_return
|
|
241
243
|
|
|
242
|
-
ui.say "On danger/danger we turn on
|
|
244
|
+
ui.say "On danger/danger we turn on #{'Permissive building of fork pull requests'.yellow} this exposes the token to Danger"
|
|
243
245
|
ui.say "You can find this setting at:"
|
|
244
246
|
ui.link "https://circleci.com/gh/#{current_repo_slug}/edit#advanced-settings\n"
|
|
245
247
|
ui.say "I'll hold..."
|
|
@@ -248,12 +250,12 @@ module Danger
|
|
|
248
250
|
|
|
249
251
|
ui.say "In order to expose an environment variable, go to:"
|
|
250
252
|
ui.link "https://circleci.com/gh/#{current_repo_slug}/edit#env-vars"
|
|
251
|
-
ui.say "The name is
|
|
253
|
+
ui.say "The name is #{'DANGER_GITHUB_API_TOKEN'.yellow} and the value is the GitHub Personal Access Token."
|
|
252
254
|
end
|
|
253
255
|
|
|
254
256
|
def unsure_token
|
|
255
|
-
ui.say "You need to expose a token called
|
|
256
|
-
ui.say "Depending on the CI system, this may need to be done on the machine (in the
|
|
257
|
+
ui.say "You need to expose a token called #{'DANGER_GITHUB_API_TOKEN'.yellow} and the value is the GitHub Personal Access Token."
|
|
258
|
+
ui.say "Depending on the CI system, this may need to be done on the machine (in the #{'~/.bashprofile'.yellow}) or in a web UI somewhere."
|
|
257
259
|
ui.say "We have a guide for all supported CI systems on danger.systems:"
|
|
258
260
|
ui.link "https://danger.systems/guides/getting_started.html#setting-up-danger-to-run-on-your-ci"
|
|
259
261
|
end
|
|
@@ -270,9 +272,9 @@ module Danger
|
|
|
270
272
|
|
|
271
273
|
def info
|
|
272
274
|
ui.header "Useful info"
|
|
273
|
-
ui.say "- One of the best ways to test out new rules locally is via
|
|
275
|
+
ui.say "- One of the best ways to test out new rules locally is via #{'bundle exec danger pr'.yellow}."
|
|
274
276
|
ui.pause 0.6
|
|
275
|
-
ui.say "- You can have Danger output all of her variables to the console via the
|
|
277
|
+
ui.say "- You can have Danger output all of her variables to the console via the #{'--verbose'.yellow} option."
|
|
276
278
|
ui.pause 0.6
|
|
277
279
|
ui.say "- You can look at the following Dangerfiles to get some more ideas:"
|
|
278
280
|
ui.pause 0.6
|
|
@@ -286,7 +288,7 @@ module Danger
|
|
|
286
288
|
ui.pause 0.6
|
|
287
289
|
|
|
288
290
|
ui.say "And you're good to go. Danger is a collaboration between Orta Therox, Gem 'Danger' McShane and Felix Krause."
|
|
289
|
-
ui.say "If you like Danger, let others know. If you want to know more, follow
|
|
291
|
+
ui.say "If you like Danger, let others know. If you want to know more, follow #{'@orta'.yellow} and #{'@KrauseFx'.yellow} on Twitter."
|
|
290
292
|
ui.say "If you don't like Danger, help us improve the project! xxx"
|
|
291
293
|
end
|
|
292
294
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
class Interviewer
|
|
3
5
|
attr_accessor :no_delay, :no_waiting, :ui
|
|
@@ -33,7 +35,7 @@ module Danger
|
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
def link(url)
|
|
36
|
-
say " ->
|
|
38
|
+
say " -> #{url.underlined}\n"
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def pause(time)
|
|
@@ -48,7 +50,7 @@ module Danger
|
|
|
48
50
|
|
|
49
51
|
def run_command(command, output_command = nil)
|
|
50
52
|
output_command ||= command
|
|
51
|
-
ui.puts "
|
|
53
|
+
ui.puts " #{output_command.magenta}"
|
|
52
54
|
system command
|
|
53
55
|
end
|
|
54
56
|
|
|
@@ -58,7 +60,7 @@ module Danger
|
|
|
58
60
|
print_info = proc do
|
|
59
61
|
possible_answers.each_with_index do |answer, i|
|
|
60
62
|
the_answer = i.zero? ? answer.underlined : answer
|
|
61
|
-
ui.print " "
|
|
63
|
+
ui.print " #{the_answer}"
|
|
62
64
|
ui.print(" /") if i != possible_answers.length - 1
|
|
63
65
|
end
|
|
64
66
|
ui.print " ]\n"
|
|
@@ -77,7 +79,7 @@ module Danger
|
|
|
77
79
|
# default to first answer
|
|
78
80
|
if answer == ""
|
|
79
81
|
answer = possible_answers[0].downcase
|
|
80
|
-
ui.puts "Using:
|
|
82
|
+
ui.puts "Using: #{answer.yellow}"
|
|
81
83
|
end
|
|
82
84
|
|
|
83
85
|
break if possible_answers.map(&:downcase).include? answer
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
class LocalSetup
|
|
3
5
|
attr_reader :dm, :cork
|
|
@@ -28,17 +30,14 @@ module Danger
|
|
|
28
30
|
cork.puts "Running your Dangerfile against this PR - https://#{gh.host}/#{source.repo_slug}/pull/#{source.pull_request_id}"
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
cork.puts "Turning on --verbose"
|
|
33
|
-
dm.verbose = true
|
|
34
|
-
end
|
|
33
|
+
dm.verbose = verbose
|
|
35
34
|
|
|
36
35
|
cork.puts
|
|
37
36
|
|
|
38
37
|
begin
|
|
39
38
|
gh.fetch_details
|
|
40
39
|
rescue Octokit::NotFound
|
|
41
|
-
cork.puts "Local repository was not found on GitHub. If you're trying to test a private repository please provide a valid API token through
|
|
40
|
+
cork.puts "Local repository was not found on GitHub. If you're trying to test a private repository please provide a valid API token through #{'DANGER_GITHUB_API_TOKEN'.yellow} environment variable."
|
|
42
41
|
return
|
|
43
42
|
end
|
|
44
43
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
class PrySetup
|
|
3
5
|
def initialize(cork)
|
|
@@ -19,7 +21,7 @@ module Danger
|
|
|
19
21
|
|
|
20
22
|
attr_reader :cork
|
|
21
23
|
|
|
22
|
-
DANGERFILE_COPY = "_Dangerfile.tmp"
|
|
24
|
+
DANGERFILE_COPY = "_Dangerfile.tmp"
|
|
23
25
|
|
|
24
26
|
def validate_pry_available(command)
|
|
25
27
|
Kernel.require "pry"
|
|
@@ -0,0 +1,91 @@
|
|
|
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 "tmpdir"
|
|
8
|
+
|
|
9
|
+
module Danger
|
|
10
|
+
class MR < Runner
|
|
11
|
+
self.summary = "Run the Dangerfile locally against GitLab Merge Requests. Does not post to the MR. Usage: danger mr <URL>"
|
|
12
|
+
self.command = "mr"
|
|
13
|
+
|
|
14
|
+
def self.options
|
|
15
|
+
[
|
|
16
|
+
["--clear-http-cache", "Clear the local http cache before running Danger locally."],
|
|
17
|
+
["--pry", "Drop into a Pry shell after evaluating the Dangerfile."],
|
|
18
|
+
["--dangerfile=<path/to/dangerfile>", "The location of your Dangerfile"]
|
|
19
|
+
]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def initialize(argv)
|
|
23
|
+
show_help = true if argv.arguments == ["-h"]
|
|
24
|
+
|
|
25
|
+
@mr_url = argv.shift_argument
|
|
26
|
+
@clear_http_cache = argv.flag?("clear-http-cache", false)
|
|
27
|
+
dangerfile = argv.option("dangerfile", "Dangerfile")
|
|
28
|
+
|
|
29
|
+
# Currently CLAide doesn't support short option like -h https://github.com/CocoaPods/CLAide/pull/60
|
|
30
|
+
# when user pass in -h, mimic the behavior of passing in --help.
|
|
31
|
+
argv = CLAide::ARGV.new ["--help"] if show_help
|
|
32
|
+
|
|
33
|
+
super
|
|
34
|
+
|
|
35
|
+
@dangerfile_path = dangerfile if File.exist?(dangerfile)
|
|
36
|
+
|
|
37
|
+
if argv.flag?("pry", false)
|
|
38
|
+
@dangerfile_path = PrySetup.new(cork).setup_pry(@dangerfile_path, MR.command)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def validate!
|
|
43
|
+
super
|
|
44
|
+
unless @dangerfile_path
|
|
45
|
+
help! "Could not find a Dangerfile."
|
|
46
|
+
end
|
|
47
|
+
unless @mr_url
|
|
48
|
+
help! "Could not find a merge-request. Usage: danger mr <URL>"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def run
|
|
53
|
+
ENV["DANGER_USE_LOCAL_GIT"] = "YES"
|
|
54
|
+
ENV["LOCAL_GIT_MR_URL"] = @mr_url if @mr_url
|
|
55
|
+
|
|
56
|
+
configure_gitlab(ENV["DANGER_TMPDIR"] || Dir.tmpdir)
|
|
57
|
+
|
|
58
|
+
env = EnvironmentManager.new(ENV, cork)
|
|
59
|
+
dm = Dangerfile.new(env, cork)
|
|
60
|
+
|
|
61
|
+
LocalSetup.new(dm, cork).setup(verbose: verbose) do
|
|
62
|
+
dm.run(
|
|
63
|
+
Danger::EnvironmentManager.danger_base_branch,
|
|
64
|
+
Danger::EnvironmentManager.danger_head_branch,
|
|
65
|
+
@dangerfile_path,
|
|
66
|
+
nil,
|
|
67
|
+
nil,
|
|
68
|
+
nil,
|
|
69
|
+
false
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def configure_gitlab(cache_dir)
|
|
77
|
+
# The require happens inline so that it won't cause exceptions when just using the `danger` gem.
|
|
78
|
+
require "gitlab"
|
|
79
|
+
|
|
80
|
+
# setup caching for GitLab calls to avoid hitting the API rate limit too quickly
|
|
81
|
+
cache_file = File.join(cache_dir, "danger_local_gitlab_cache")
|
|
82
|
+
HTTPCache.new(cache_file, clear_cache: @clear_http_cache)
|
|
83
|
+
|
|
84
|
+
# Configure GitLab client
|
|
85
|
+
Gitlab.configure do |config|
|
|
86
|
+
config.endpoint = ENV["DANGER_GITLAB_API_BASE_URL"] || ENV.fetch("CI_API_V4_URL", "https://gitlab.com/api/v4")
|
|
87
|
+
config.private_token = ENV["DANGER_GITLAB_API_TOKEN"]
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
data/lib/danger/commands/pr.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/commands/local_helpers/http_cache"
|
|
2
4
|
require "danger/commands/local_helpers/pry_setup"
|
|
3
5
|
require "faraday/http_cache"
|
|
@@ -7,8 +9,8 @@ require "tmpdir"
|
|
|
7
9
|
|
|
8
10
|
module Danger
|
|
9
11
|
class PR < Runner
|
|
10
|
-
self.summary = "Run the Dangerfile locally against Pull Requests (works with forks, too). Does not post to the PR. Usage: danger pr <URL>"
|
|
11
|
-
self.command = "pr"
|
|
12
|
+
self.summary = "Run the Dangerfile locally against Pull Requests (works with forks, too). Does not post to the PR. Usage: danger pr <URL>"
|
|
13
|
+
self.command = "pr"
|
|
12
14
|
|
|
13
15
|
def self.options
|
|
14
16
|
[
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
class Runner < CLAide::Command
|
|
3
5
|
require "danger/commands/init"
|
|
@@ -6,6 +8,7 @@ module Danger
|
|
|
6
8
|
require "danger/commands/staging"
|
|
7
9
|
require "danger/commands/systems"
|
|
8
10
|
require "danger/commands/pr"
|
|
11
|
+
require "danger/commands/mr"
|
|
9
12
|
|
|
10
13
|
# manually set claide plugins as a subcommand
|
|
11
14
|
require "claide_plugin"
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
class Systems < Runner
|
|
3
5
|
self.abstract_command = true
|
|
@@ -11,7 +13,7 @@ module Danger
|
|
|
11
13
|
|
|
12
14
|
def run
|
|
13
15
|
here = File.dirname(__FILE__)
|
|
14
|
-
ci_source_paths = Dir.glob(here
|
|
16
|
+
ci_source_paths = Dir.glob("#{here}/../ci_source/*.rb")
|
|
15
17
|
|
|
16
18
|
require "yard"
|
|
17
19
|
# Pull out all the Danger::CI subclasses docs
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class String
|
|
2
4
|
# @return [String] the plural form of self determined by count
|
|
3
5
|
def danger_pluralize(count)
|
|
@@ -6,10 +8,10 @@ class String
|
|
|
6
8
|
|
|
7
9
|
# @return [String] converts to underscored, lowercase form
|
|
8
10
|
def danger_underscore
|
|
9
|
-
self.gsub(/::/, "/"
|
|
10
|
-
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'
|
|
11
|
-
gsub(/([a-z\d])([A-Z])/, '\1_\2'
|
|
12
|
-
tr("-"
|
|
11
|
+
self.gsub(/::/, "/").
|
|
12
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
|
13
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
|
14
|
+
tr("-", "_").
|
|
13
15
|
downcase
|
|
14
16
|
end
|
|
15
17
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# So much was ripped direct from CocoaPods-Core - thanks!
|
|
2
4
|
|
|
3
5
|
require "danger/danger_core/dangerfile_dsl"
|
|
@@ -185,8 +187,9 @@ module Danger
|
|
|
185
187
|
contents.encode!("UTF-8")
|
|
186
188
|
end
|
|
187
189
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
sanitised_contents = contents.tr("“”‘’‛", %(""'''))
|
|
191
|
+
if sanitised_contents != contents
|
|
192
|
+
contents = sanitised_contents
|
|
190
193
|
ui.puts "Your #{path.basename} has had smart quotes sanitised. " \
|
|
191
194
|
"To avoid issues in the future, you should not use " \
|
|
192
195
|
"TextEdit for editing it. If you are not using TextEdit, " \
|
|
@@ -217,7 +220,7 @@ module Danger
|
|
|
217
220
|
|
|
218
221
|
ui.section("Results:") do
|
|
219
222
|
%i(errors warnings messages).each do |key|
|
|
220
|
-
formatted = key.to_s.capitalize
|
|
223
|
+
formatted = "#{key.to_s.capitalize}:"
|
|
221
224
|
title = case key
|
|
222
225
|
when :errors
|
|
223
226
|
formatted.red
|
|
@@ -271,7 +274,7 @@ module Danger
|
|
|
271
274
|
|
|
272
275
|
def setup_for_running(base_branch, head_branch)
|
|
273
276
|
env.ensure_danger_branches_are_setup
|
|
274
|
-
env.scm.diff_for_folder("."
|
|
277
|
+
env.scm.diff_for_folder(".", from: base_branch, to: head_branch, lookup_top_level: true)
|
|
275
278
|
end
|
|
276
279
|
|
|
277
280
|
def run(base_branch, head_branch, dangerfile_path, danger_id, new_comment, remove_previous_comments, report_results = true)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "danger/ci_source/ci_source"
|
|
2
4
|
require "danger/request_sources/request_source"
|
|
3
5
|
|
|
@@ -19,12 +21,12 @@ module Danger
|
|
|
19
21
|
|
|
20
22
|
# @return [String] danger's default head branch
|
|
21
23
|
def self.danger_head_branch
|
|
22
|
-
"danger_head"
|
|
24
|
+
"danger_head"
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
# @return [String] danger's default base branch
|
|
26
28
|
def self.danger_base_branch
|
|
27
|
-
"danger_base"
|
|
29
|
+
"danger_base"
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
def initialize(env, ui = nil, danger_id = "danger")
|
|
@@ -87,13 +89,14 @@ module Danger
|
|
|
87
89
|
private
|
|
88
90
|
|
|
89
91
|
def get_repo_source(repo_url)
|
|
90
|
-
|
|
92
|
+
case repo_url
|
|
93
|
+
when /github/i
|
|
91
94
|
RequestSources::GitHub
|
|
92
|
-
|
|
95
|
+
when /gitlab/i
|
|
93
96
|
RequestSources::GitLab
|
|
94
|
-
|
|
97
|
+
when /bitbucket\.(org|com)/i
|
|
95
98
|
RequestSources::BitbucketCloud
|
|
96
|
-
|
|
99
|
+
when /\.visualstudio\.com/i, /dev\.azure\.com/i
|
|
97
100
|
RequestSources::VSTS
|
|
98
101
|
end
|
|
99
102
|
end
|
|
@@ -112,12 +115,12 @@ module Danger
|
|
|
112
115
|
end
|
|
113
116
|
|
|
114
117
|
def ui_display_no_request_source_error_message(ui, env, title, subtitle)
|
|
115
|
-
ui.title "Could not set up API to Code Review site for Danger\n"
|
|
118
|
+
ui.title "Could not set up API to Code Review site for Danger\n"
|
|
116
119
|
ui.puts title
|
|
117
120
|
ui.puts subtitle
|
|
118
|
-
ui.puts "\nFound these keys in your ENV: #{env.keys.join(', '
|
|
119
|
-
ui.puts "\nFailing the build, Danger cannot run without API access."
|
|
120
|
-
ui.puts "You can see more information at https://danger.systems/guides/getting_started.html"
|
|
121
|
+
ui.puts "\nFound these keys in your ENV: #{env.keys.join(', ')}."
|
|
122
|
+
ui.puts "\nFailing the build, Danger cannot run without API access."
|
|
123
|
+
ui.puts "You can see more information at https://danger.systems/guides/getting_started.html"
|
|
121
124
|
end
|
|
122
125
|
|
|
123
126
|
def travis_note
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
class Executor
|
|
3
5
|
def initialize(system_env)
|
|
@@ -61,7 +63,7 @@ module Danger
|
|
|
61
63
|
unless EnvironmentManager.pr?(system_env)
|
|
62
64
|
ci_name = EnvironmentManager.local_ci_source(system_env).name.split("::").last
|
|
63
65
|
|
|
64
|
-
msg = "Not a #{ci_name} #{commit_request(ci_name)} - skipping `danger` run. "
|
|
66
|
+
msg = +"Not a #{ci_name} #{commit_request(ci_name)} - skipping `danger` run. "
|
|
65
67
|
# circle won't run danger properly if the commit is pushed and build runs before the PR exists
|
|
66
68
|
# https://danger.systems/guides/troubleshooting.html#circle-ci-doesnt-run-my-build-consistently
|
|
67
69
|
# the best solution is to enable `fail_if_no_pr`, and then re-run the job once the PR is up
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Danger
|
|
2
4
|
class BaseMessage
|
|
3
|
-
attr_accessor :message, :file, :line, :type
|
|
5
|
+
attr_accessor :message, :file, :line, :type, :start_line, :side, :start_side
|
|
4
6
|
|
|
5
|
-
def initialize(type:, message:, file: nil, line: nil)
|
|
7
|
+
def initialize(type:, message:, file: nil, line: nil, start_line: nil, side: nil, start_side: nil)
|
|
6
8
|
@type = type
|
|
7
9
|
@message = message
|
|
8
10
|
@file = file
|
|
9
11
|
@line = line
|
|
12
|
+
@start_line = start_line
|
|
13
|
+
@side = side
|
|
14
|
+
@start_side = start_side
|
|
10
15
|
end
|
|
11
16
|
|
|
12
17
|
def compare_by_file_and_line(other)
|
|
@@ -4,8 +4,21 @@ require "danger/danger_core/messages/base"
|
|
|
4
4
|
|
|
5
5
|
module Danger
|
|
6
6
|
class Markdown < BaseMessage
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
VALID_SIDES = %w(LEFT RIGHT).freeze
|
|
8
|
+
|
|
9
|
+
def initialize(message, file = nil, line = nil, start_line: nil, side: nil, start_side: nil)
|
|
10
|
+
validate_side!(:side, side)
|
|
11
|
+
validate_side!(:start_side, start_side)
|
|
12
|
+
|
|
13
|
+
super(
|
|
14
|
+
type: :markdown,
|
|
15
|
+
message: message,
|
|
16
|
+
file: file,
|
|
17
|
+
line: line,
|
|
18
|
+
start_line: start_line,
|
|
19
|
+
side: side,
|
|
20
|
+
start_side: start_side
|
|
21
|
+
)
|
|
9
22
|
end
|
|
10
23
|
|
|
11
24
|
def ==(other)
|
|
@@ -14,20 +27,29 @@ module Danger
|
|
|
14
27
|
|
|
15
28
|
other.message == message &&
|
|
16
29
|
other.file == file &&
|
|
17
|
-
other.line == line
|
|
30
|
+
other.line == line &&
|
|
31
|
+
other.start_line == start_line &&
|
|
32
|
+
other.side == side &&
|
|
33
|
+
other.start_side == start_side
|
|
18
34
|
end
|
|
19
35
|
|
|
20
36
|
def hash
|
|
21
37
|
h = 1
|
|
22
38
|
h = h * 31 + message.hash
|
|
23
39
|
h = h * 17 + file.hash
|
|
24
|
-
h * 17 + line.hash
|
|
40
|
+
h = h * 17 + line.hash
|
|
41
|
+
h = h * 17 + start_line.hash
|
|
42
|
+
h = h * 17 + side.hash
|
|
43
|
+
h * 17 + start_side.hash
|
|
25
44
|
end
|
|
26
45
|
|
|
27
46
|
def to_s
|
|
28
47
|
extra = []
|
|
29
|
-
extra << "file: #{file}"
|
|
30
|
-
extra << "line: #{line}"
|
|
48
|
+
extra << "file: #{file}" if file
|
|
49
|
+
extra << "line: #{line}" if line
|
|
50
|
+
extra << "start_line: #{start_line}" if start_line
|
|
51
|
+
extra << "side: #{side}" if side
|
|
52
|
+
extra << "start_side: #{start_side}" if start_side
|
|
31
53
|
|
|
32
54
|
"Markdown #{message} { #{extra.join ', '} }"
|
|
33
55
|
end
|
|
@@ -37,5 +59,13 @@ module Danger
|
|
|
37
59
|
|
|
38
60
|
compare_by_file_and_line(other)
|
|
39
61
|
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def validate_side!(name, value)
|
|
66
|
+
return if value.nil? || VALID_SIDES.include?(value)
|
|
67
|
+
|
|
68
|
+
raise ArgumentError, "#{name} must be LEFT or RIGHT"
|
|
69
|
+
end
|
|
40
70
|
end
|
|
41
71
|
end
|