Skip to content

Commit

Permalink
remove (revert back) not used ruby_version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Oct 24, 2024
1 parent 4afe079 commit e14dc56
Showing 1 changed file with 0 additions and 90 deletions.
90 changes: 0 additions & 90 deletions bundler/lib/dependabot/bundler/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,96 +35,6 @@ def self.detected_bundler_version(lockfile)
"unspecified"
end
end

sig do
params(
gemfile: T.nilable(Dependabot::DependencyFile),
lockfile: T.nilable(Dependabot::DependencyFile)
).returns(Gem::Version)
end
def self.ruby_version(gemfile, lockfile)
ruby_version = ruby_version_from_ruby_version_file

ruby_version = ruby_version_from_lockfile(lockfile) if ruby_version.nil?

ruby_version = ruby_version_from_definition(gemfile, lockfile) if ruby_version.nil?

ruby_version = RUBY_VERSION if ruby_version.nil?

Gem::Version.new(ruby_version)
end

sig do
params(
lockfile: T.nilable(Dependabot::DependencyFile)
).returns(T.nilable(String))
end
def self.ruby_version_from_lockfile(lockfile)
return nil unless lockfile

ruby_version = lockfile.content&.match(/RUBY VERSION\s+(?<version>[^\s]+)/)&.named_captures&.fetch(
"version", nil
)
ruby_version
end

sig do
params(
gemfile: T.nilable(Dependabot::DependencyFile),
lockfile: T.nilable(Dependabot::DependencyFile)
)
.returns(T.nilable(String))
end
def self.ruby_version_from_definition(gemfile, lockfile)
gemfile_name = gemfile&.name
return nil unless gemfile_name

ruby_version = T.let(build_definition(gemfile, lockfile).ruby_version, T.nilable(::Bundler::RubyVersion))

gem_version = T.let(ruby_version&.gem_version, T.nilable(Gem::Version))

return nil unless gem_version

gem_version.to_s
end

sig do
params(
gemfile: T.nilable(Dependabot::DependencyFile),
lockfile: T.nilable(Dependabot::DependencyFile)
).returns(::Bundler::Definition)
end
def self.build_definition(gemfile, lockfile)
gemfile_name = gemfile&.name
lockfile_name = lockfile&.name
T.let(
::Bundler::Definition.build(
gemfile_name,
lockfile_name,
gems: []
), ::Bundler::Definition
)
end

sig { returns(T.nilable(String)) }
def self.ruby_version_from_ruby_version_file
# Ensure file_content is either a String or nil
file_content = T.let(::Bundler.read_file(".ruby-version"), T.nilable(String))

return nil unless file_content.is_a?(String)

# Regex match to extract the Ruby version
ruby_version = if /^ruby(-|\s+)?([^\s#]+)/ =~ file_content
T.let(::Regexp.last_match(2), T.nilable(String))
else
T.let(file_content.strip, T.nilable(String))
end

ruby_version
rescue SystemCallError
# Handle .ruby-version file not existing, return nil
nil
end
end
end
end

0 comments on commit e14dc56

Please sign in to comment.