Skip to content

Commit

Permalink
Merge pull request #4050 from dependabot/feelepxyz/dry-run-cache-clon…
Browse files Browse the repository at this point in the history
…e-repo

Dry-run: cache cloned repos
  • Loading branch information
feelepxyz committed Jul 15, 2021
2 parents 108af92 + 215143f commit 13b9071
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions bin/dry-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
security_advisories: [],
security_updates_only: false,
ignore_conditions: [],
pull_request: false,
pull_request: false
}

unless ENV["LOCAL_GITHUB_ACCESS_TOKEN"].to_s.strip.empty?
Expand Down Expand Up @@ -201,11 +201,9 @@
opts_opt_desc = "Comma separated list of updater options, "\
"available options depend on PACKAGE_MANAGER"
opts.on("--updater-options OPTIONS", opts_opt_desc) do |value|
$options[:updater_options] = Hash[
value.split(",").map do |o|
[o.strip.downcase.to_sym, true]
end
]
$options[:updater_options] = value.split(",").map do |o|
[o.strip.downcase.to_sym, true]
end.to_h
end

opts.on("--security-updates-only",
Expand Down Expand Up @@ -255,7 +253,7 @@ def show_diff(original_file, updated_file)
puts
puts " ± #{original_file.name}"
puts " ~~~"
puts diff.lines.map { |line| " " + line }.join("")
puts diff.lines.map { |line| " " + line }.join
puts " ~~~"
end

Expand Down Expand Up @@ -436,8 +434,8 @@ def handle_dependabot_error(error:, dependency:)
raise error
end

puts " => handled error whilst updating #{dependency.name}: #{error_details.fetch(:'error-type')} "\
"#{error_details.fetch(:'error-detail')}"
puts " => handled error whilst updating #{dependency.name}: #{error_details.fetch(:"error-type")} "\
"#{error_details.fetch(:"error-detail")}"
end
# rubocop:enable Metrics/MethodLength

Expand All @@ -453,10 +451,7 @@ def handle_dependabot_error(error:, dependency:)

always_clone = Dependabot::Utils.
always_clone_for_package_manager?($package_manager)
if $options[:clone] || always_clone
$repo_contents_path = Dir.mktmpdir
puts "=> cloning into #{$repo_contents_path}"
end
$repo_contents_path = File.expand_path(File.join("tmp", $repo_name.split("/"))) if $options[:clone] || always_clone

fetcher_args = {
source: $source,
Expand All @@ -476,8 +471,20 @@ def handle_dependabot_error(error:, dependency:)
)

fetcher = Dependabot::FileFetchers.for_package_manager($package_manager).new(**fetcher_args)
$files = if $options[:clone] || always_clone
$files = if $repo_contents_path
if $options[:cache_steps].include?("files") && Dir.exist?($repo_contents_path)
puts "=> reading cloned repo from #{$repo_contents_path}"
else
puts "=> cloning into #{$repo_contents_path}"
FileUtils.rm_rf($repo_contents_path)
end
fetcher.clone_repo_contents
if $options[:commit]
Dir.chdir($repo_contents_path) do
puts "=> checking out commit #{$options[:commit]}"
Dependabot::SharedHelpers.run_shell_command("git checkout #{$options[:commit]}")
end
end
fetcher.files
else
cached_dependency_files_read do
Expand All @@ -492,7 +499,7 @@ def handle_dependabot_error(error:, dependency:)
repo_contents_path: $repo_contents_path,
source: $source,
credentials: $options[:credentials],
reject_external_code: $options[:reject_external_code],
reject_external_code: $options[:reject_external_code]
)

dependencies = cached_read("dependencies") { parser.parse }
Expand Down Expand Up @@ -527,7 +534,7 @@ def ignored_versions_for(dep)
)
end
Dependabot::Config::UpdateConfig.new(ignore_conditions: ignore_conditions).
ignored_versions_for(dep, security_updates_only: $options[:security_updates_only])
ignored_versions_for(dep, security_updates_only: $options[:security_updates_only])
else
$update_config.ignored_versions_for(dep)
end
Expand Down

0 comments on commit 13b9071

Please sign in to comment.