Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
243 changes: 130 additions & 113 deletions Gemfile.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions bin/spec/dry-run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ def run_with_options(options)
"--commit abc1234",
"--updater-options goprivate=true,record_ecosystem_versions"
].each do |option_str|
option_name = option_str.split.first
option_value = option_str.split.last

it "accepts #{option_name} option" do
it "accepts #{option_str.split.first} option" do
option_name = option_str.split.first
option_value = option_str.split.last
stdout, stderr, = run_with_options([option_name, option_value])

# Ensure it doesn't show usage help (which would indicate option parsing error)
Expand Down
19 changes: 10 additions & 9 deletions bun/lib/dependabot/bun/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,19 @@ def path_dependency_details_from_manifest(file)

resolution_deps = resolution_objects.flat_map(&:to_a)
.map do |path, value|
# skip dependencies that contain invalid values such as inline comments, null, etc.
# skip dependencies that contain invalid values
# such as inline comments, null, etc.

unless value.is_a?(String)
Dependabot.logger.warn(
"File fetcher: Skipping dependency \"#{path}\" " \
"with value: \"#{value}\""
)
unless value.is_a?(String)
Dependabot.logger.warn(
"File fetcher: Skipping dependency \"#{path}\" " \
"with value: \"#{value}\""
)

next
end
next
end

convert_dependency_path_to_name(path, value)
convert_dependency_path_to_name(path, value)
end

path_starts = PATH_DEPENDENCY_STARTS
Expand Down
12 changes: 6 additions & 6 deletions bun/lib/dependabot/bun/file_fetcher/path_dependency_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def details_from_yarn_lock
path_starts = FileFetcher::PATH_DEPENDENCY_STARTS
parsed_yarn_lock.to_a
.find do |n, _|
next false unless n.split(/(?<=\w)\@/).first == dependency_name
next false unless n.split(/(?<=\w)\@/).first == dependency_name

T.must(n.split(/(?<=\w)\@/).last).start_with?(*path_starts)
T.must(n.split(/(?<=\w)\@/).last).start_with?(*path_starts)
end&.last
end

Expand All @@ -82,7 +82,7 @@ def details_from_npm_lock
path_starts = FileFetcher::NPM_PATH_DEPENDENCY_STARTS
path_deps = parsed_package_lock.fetch("dependencies", []).to_a
.select do |_, v|
v.fetch("version", "").start_with?(*path_starts)
v.fetch("version", "").start_with?(*path_starts)
end
path_deps.find { |n, _| n == dependency_name }&.last
end
Expand Down Expand Up @@ -131,10 +131,10 @@ def replace_yarn_lockfile_paths(dependencies_hash)
path_from_base =
parsed_yarn_lock.to_a
.find do |n, _|
next false unless n.split(/(?<=\w)\@/).first == name
next false unless n.split(/(?<=\w)\@/).first == name

T.must(n.split(/(?<=\w)\@/).last)
.start_with?(*FileFetcher::PATH_DEPENDENCY_STARTS)
T.must(n.split(/(?<=\w)\@/).last)
.start_with?(*FileFetcher::PATH_DEPENDENCY_STARTS)
end&.first&.split(/(?<=\w)\@/)&.last

next unless path_from_base
Expand Down
6 changes: 3 additions & 3 deletions bun/lib/dependabot/bun/file_updater/package_json_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def updated_requirements(dependency)
updated_requirement_pairs =
dependency.requirements.zip(T.must(dependency.previous_requirements))
.reject do |new_req, old_req|
next true if new_req == old_req
next false unless old_req&.fetch(:source).nil?
next true if new_req == old_req
next false unless old_req&.fetch(:source).nil?

new_req[:requirement] == old_req&.fetch(:requirement)
new_req[:requirement] == old_req&.fetch(:requirement)
end

updated_requirement_pairs
Expand Down
2 changes: 1 addition & 1 deletion bun/lib/dependabot/bun/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def original_source(updated_dependency)
sources =
updated_dependency
.requirements.map { |r| r.fetch(:source) }
.uniq.compact
.uniq.compact
.sort_by do |source|
Package::RegistryFinder.central_registry?(source[:url]) ? 1 : 0
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def possible_versions(filter_ignored: true)
def possible_previous_releases
(package_details&.releases || [])
.reject do |r|
r.version.prerelease? && !related_to_current_pre?(T.unsafe(r.version))
r.version.prerelease? && !related_to_current_pre?(T.unsafe(r.version))
end
.sort_by(&:version).reverse
end
Expand Down
14 changes: 7 additions & 7 deletions bun/lib/dependabot/bun/update_checker/version_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def resolve_latest_previous_version(dep, updated_version)
.possible_previous_versions_with_details
.map(&:first)
reqs = dep.requirements.filter_map { |r| r[:requirement] }
.map { |r| requirement_class.requirements_array(r) }
.map { |r| requirement_class.requirements_array(r) }

# Pick the lowest version from the max possible version from all
# requirements. This matches the logic when combining the same
Expand Down Expand Up @@ -720,12 +720,12 @@ def version_for_dependency(dep)
return version_class.new(dep.version) if dep.version && version_class.correct?(dep.version)

dep.requirements.filter_map { |r| r[:requirement] }
.reject { |req_string| req_string.start_with?("<") }
.select { |req_string| req_string.match?(version_regex) }
.map { |req_string| req_string.match(version_regex) }
.select { |version| version_class.correct?(version.to_s) }
.map { |version| version_class.new(version.to_s) }
.max
.reject { |req_string| req_string.start_with?("<") }
.select { |req_string| req_string.match?(version_regex) }
.map { |req_string| req_string.match(version_regex) }
.select { |version| version_class.correct?(version.to_s) }
.map { |version| version_class.new(version.to_s) }
.max
end

sig { returns(T.class_of(Dependabot::Version)) }
Expand Down
2 changes: 1 addition & 1 deletion bundler/helpers/v2/lib/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def self.git_specs(**args)

git_specs = Bundler::Definition.build(args.fetch(:gemfile_name), nil, {}).dependencies
.select do |spec|
spec.source.is_a?(Bundler::Source::Git)
spec.source.is_a?(Bundler::Source::Git)
end
git_specs.map do |spec|
# Piggy-back off some private Bundler methods to configure the
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/dependabot/bundler/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def updated_dependency_files
vendor_updater
.updated_files(base_directory: base_dir)
.each do |file|
updated_files << file
updated_files << file
end

updated_files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ def new_requirement_string(
new_requirement_string =
updated_requirement.split(",")
.map do |r|
req_string = serialized_req(r, use_equality_operator)
req_string = %(#{open_quote}#{req_string}#{close_quote})
req_string = req_string.delete(" ") unless space_after_specifier
req_string
req_string = serialized_req(r, use_equality_operator)
req_string = %(#{open_quote}#{req_string}#{close_quote})
req_string = req_string.delete(" ") unless space_after_specifier
req_string
end.join(", ")

new_requirement_string
Expand Down
6 changes: 3 additions & 3 deletions bundler/lib/dependabot/bundler/metadata_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def find_source_from_gemspec_download

T.must(rubygems_marshalled_gemspec_response).gsub("\x06;", "\n")
.scan(Source::SOURCE_REGEX) do
github_urls << Regexp.last_match.to_s
github_urls << Regexp.last_match.to_s
end

source_url = github_urls.find do |url|
Expand All @@ -127,8 +127,8 @@ def changelog_url_from_gemspec_download

T.must(rubygems_marshalled_gemspec_response).gsub("\x06;", "\n")
.scan(Dependabot::Source::SOURCE_REGEX) do
github_urls << (Regexp.last_match.to_s +
T.must(T.must(Regexp.last_match).post_match.split("\n").first))
github_urls << (Regexp.last_match.to_s +
T.must(T.must(Regexp.last_match).post_match.split("\n").first))
end

github_urls.find do |url|
Expand Down
16 changes: 8 additions & 8 deletions bundler/lib/dependabot/bundler/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ def requirements_unlocked_or_can_be?

dependency.specific_requirements
.all? do |req|
file = T.must(dependency_files.find { |f| f.name == req.fetch(:file) })
updated = FileUpdater::RequirementReplacer.new(
dependency: dependency,
file_type: file.name.end_with?("gemspec") ? :gemspec : :gemfile,
updated_requirement: "whatever"
).rewrite(file.content)

updated != file.content
file = T.must(dependency_files.find { |f| f.name == req.fetch(:file) })
updated = FileUpdater::RequirementReplacer.new(
dependency: dependency,
file_type: file.name.end_with?("gemspec") ? :gemspec : :gemfile,
updated_requirement: "whatever"
).rewrite(file.content)

updated != file.content
end
end

Expand Down
10 changes: 5 additions & 5 deletions bundler/lib/dependabot/bundler/update_checker/file_preparer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ def updated_version_req_lower_bound(filename) # rubocop:disable Metrics/Cyclomat
else
version_for_requirement =
dependency.requirements.map { |r| r[:requirement] }
.reject { |req_string| req_string.start_with?("<") }
.select { |req_string| req_string.match?(VERSION_REGEX) }
.map { |req_string| req_string.match(VERSION_REGEX)&.to_s }
.select { |version| Bundler::Version.correct?(version) }
.max_by { |version| Bundler::Version.new(version) }
.reject { |req_string| req_string.start_with?("<") }
.select { |req_string| req_string.match?(VERSION_REGEX) }
.map { |req_string| req_string.match(VERSION_REGEX)&.to_s }
.select { |version| Bundler::Version.correct?(version) }
.max_by { |version| Bundler::Version.new(version) }

">= #{version_for_requirement || 0}"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def latest_git_version_details

source_details =
dependency.requirements.map { |r| r.fetch(:source) }
.uniq.compact.first
.uniq.compact.first

SharedHelpers.with_git_configured(credentials: credentials) do
in_a_native_bundler_context do |tmp_dir|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def in_a_native_bundler_context(error_handling: true, &_blk)
SharedHelpers
.in_a_temporary_repo_directory(base_directory,
repo_contents_path) do |tmp_dir|
write_temporary_dependency_files
write_temporary_dependency_files

yield(tmp_dir.to_s)
yield(tmp_dir.to_s)
end
rescue SharedHelpers::HelperSubprocessFailed => e
retry_count ||= 0
Expand Down
18 changes: 9 additions & 9 deletions bundler/spec/dependabot/bundler/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@
it "raises a helpful error" do
expect { parser.parse }
.to raise_error do |error|
expect(error.class).to eq(Dependabot::DependencyFileNotEvaluatable)
expect(error.message)
.to include("No plugin sources available for aws-s3")
expect(error.class).to eq(Dependabot::DependencyFileNotEvaluatable)
expect(error.message)
.to include("No plugin sources available for aws-s3")
end
end
end
Expand Down Expand Up @@ -425,8 +425,8 @@
it "raises a helpful error" do
expect { parser.parse }
.to raise_error do |error|
expect(error.class).to eq(Dependabot::DependencyFileNotEvaluatable)
expect(error.message.encoding.to_s).to eq("UTF-8")
expect(error.class).to eq(Dependabot::DependencyFileNotEvaluatable)
expect(error.message.encoding.to_s).to eq("UTF-8")
end
end

Expand All @@ -436,10 +436,10 @@
it "raises a helpful error" do
expect { parser.parse }
.to raise_error do |error|
expect(error.message)
.to start_with("Error evaluating your dependency files")
expect(error.class)
.to eq(Dependabot::DependencyFileNotEvaluatable)
expect(error.message)
.to start_with("Error evaluating your dependency files")
expect(error.class)
.to eq(Dependabot::DependencyFileNotEvaluatable)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions bundler/spec/dependabot/bundler/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1571,8 +1571,8 @@
}]
end

removed = "vendor/cache/dependabot-test-ruby-package-81073f9462f2"
added = "vendor/cache/dependabot-test-ruby-package-1c6331732c41"
let(:removed) { "vendor/cache/dependabot-test-ruby-package-81073f9462f2" }
let(:added) { "vendor/cache/dependabot-test-ruby-package-1c6331732c41" }

it "vendors the new dependency" do
expect(updater.updated_dependency_files.map(&:name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
it "raises a PrivateSourceAuthenticationFailure error" do
expect { latest_resolvable_version_details }
.to raise_error(Dependabot::PrivateSourceAuthenticationFailure) do |error|
expect(error.message).to include(": rubygems.pkg.github.com")
expect(error.message).to include(": rubygems.pkg.github.com")
end
end
end
Expand Down Expand Up @@ -325,8 +325,8 @@
it "raises a useful error" do
expect { latest_resolvable_version_details }
.to raise_error(Dependabot::DependencyFileNotEvaluatable) do |error|
# Test that the temporary path isn't included in the error message
expect(error.message).not_to include("dependabot_20")
# Test that the temporary path isn't included in the error message
expect(error.message).not_to include("dependabot_20")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ def parse_response(response, index)
.map(&:strip)
.reject(&:empty?)
.filter_map do |line|
JSON.parse(line)
rescue JSON::ParserError => e
Dependabot.logger.warn("Failed to parse line in sparse index: #{e.message}")
nil
JSON.parse(line)
rescue JSON::ParserError => e
Dependabot.logger.warn("Failed to parse line in sparse index: #{e.message}")
nil
end

{ "versions" => parsed_response }
Expand Down
8 changes: 4 additions & 4 deletions cargo/lib/dependabot/cargo/update_checker/file_preparer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ def lower_bound_version
else
version_from_requirement =
dependency.requirements.filter_map { |r| r.fetch(:requirement) }
.flat_map { |req_str| Cargo::Requirement.new(req_str) }
.flat_map(&:requirements)
.reject { |req_array| req_array.first.start_with?("<") }
.map(&:last)
.flat_map { |req_str| Cargo::Requirement.new(req_str) }
.flat_map(&:requirements)
.reject { |req_array| req_array.first.start_with?("<") }
.map(&:last)
.max&.to_s

version_from_requirement || 0
Expand Down
Loading
Loading