Skip to content

Commit

Permalink
Merge pull request #4820 from deivid-rodriguez/fix-ruby-error-detection
Browse files Browse the repository at this point in the history
Fix Ruby version conflict error detection for new Bundler versions
  • Loading branch information
jurre authored Mar 21, 2022
2 parents cd97bc9 + e9a759b commit ea8fbaf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
31 changes: 1 addition & 30 deletions bundler/lib/dependabot/bundler/file_updater/lockfile_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class LockfileUpdater
require_relative "gemspec_updater"
require_relative "gemspec_sanitizer"
require_relative "gemspec_dependency_name_finder"
require_relative "ruby_requirement_setter"

LOCKFILE_ENDING =
/(?<ending>\s*(?:RUBY VERSION|BUNDLED WITH).*)/m.freeze
Expand Down Expand Up @@ -80,23 +79,10 @@ def build_updated_lockfile
)
end
post_process_lockfile(lockfile_body)
rescue SharedHelpers::HelperSubprocessFailed => e
raise unless ruby_lock_error?(e)

@dont_lock_ruby_version = true
retry
end

def ruby_lock_error?(error)
return false unless error.error_class == "Bundler::VersionConflict"
return false unless error.message.include?(" for gem \"ruby\0\"")
return false if @dont_lock_ruby_version

dependency_files.any? { |f| f.name.end_with?(".gemspec") }
end

def write_temporary_dependency_files
File.write(gemfile.name, prepared_gemfile_content(gemfile))
File.write(gemfile.name, updated_gemfile_content(gemfile))
File.write(lockfile.name, sanitized_lockfile_body)

top_level_gemspecs.each do |gemspec|
Expand Down Expand Up @@ -236,21 +222,6 @@ def replacement_version_for_gemspec(gemspec_content)
end
# rubocop:enable Metrics/PerceivedComplexity

def prepared_gemfile_content(file)
content =
GemfileUpdater.new(
dependencies: dependencies,
gemfile: file
).updated_gemfile_content
return content if @dont_lock_ruby_version

top_level_gemspecs.each do |gs|
content = RubyRequirementSetter.new(gemspec: gs).rewrite(content)
end

content
end

def updated_gemfile_content(file)
GemfileUpdater.new(
dependencies: dependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def error_due_to_restrictive_upper_bound?(error)
end

def ruby_lock_error?(error)
return false unless error.message.include?(" for gem \"ruby\0\"")
return false unless error.message.include?(" for the Ruby\0 version") || # Bundler 2
error.message.include?(" for gem \"ruby\0\"") # Bundler 1
return false if @gemspec_ruby_unlocked

dependency_files.any? { |f| f.name.end_with?(".gemspec") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,15 @@
to eq(Gem::Version.new("2.0.1"))
end

context "that isn't satisfied by the dependencies", :bundler_v2_only do
context "that isn't satisfied by the dependencies" do
let(:dependency_files) do
bundler_project_dependency_files("imports_gemspec_version_clash_old_required_ruby_no_lockfile")
end
let(:current_version) { "3.0.1" }

it "raises a DependencyFileNotResolvable error" do
expect { subject }.
to raise_error(Dependabot::DependencyFileNotResolvable)
it "ignores the minimum ruby version in the gemspec" do
expect(resolver.latest_resolvable_version_details[:version]).
to eq(Gem::Version.new("7.2.0"))
end
end
end
Expand Down

0 comments on commit ea8fbaf

Please sign in to comment.