Class: Dependabot::Bundler::UpdateChecker::FilePreparer
- Inherits:
-
Object
- Object
- Dependabot::Bundler::UpdateChecker::FilePreparer
- Defined in:
- lib/dependabot/bundler/update_checker/file_preparer.rb
Overview
This class takes a set of dependency files and sanitizes them for use in UpdateCheckers::Ruby::Bundler. In particular, it:
-
Removes any version requirement on the dependency being updated (in the Gemfile)
-
Sanitizes any provided gemspecs to remove file imports etc. (since Dependabot doesn’t pull down the entire repo). This process is imperfect - an alternative would be to clone the repo
-
Sets the ruby version in the Gemfile to be the lowest possible version allowed by the gemspec, if the gemspec has a required ruby version range
Constant Summary collapse
- VERSION_REGEX =
/[0-9]+(?:\.[A-Za-z0-9\-_]+)*/
Instance Method Summary collapse
-
#gemspec_sources ⇒ Object
Can’t be a constant because some of these don’t exist in bundler 1.15, which Heroku uses, which causes an exception on boot.
-
#initialize(dependency_files:, dependency:, remove_git_source: false, unlock_requirement: true, replacement_git_pin: nil, latest_allowable_version: nil, lock_ruby_version: true) ⇒ FilePreparer
constructor
A new instance of FilePreparer.
-
#prepared_dependency_files ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(dependency_files:, dependency:, remove_git_source: false, unlock_requirement: true, replacement_git_pin: nil, latest_allowable_version: nil, lock_ruby_version: true) ⇒ FilePreparer
Returns a new instance of FilePreparer.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dependabot/bundler/update_checker/file_preparer.rb', line 40 def initialize(dependency_files:, dependency:, remove_git_source: false, unlock_requirement: true, replacement_git_pin: nil, latest_allowable_version: nil, lock_ruby_version: true) @dependency_files = dependency_files @dependency = dependency @remove_git_source = remove_git_source @unlock_requirement = unlock_requirement @replacement_git_pin = replacement_git_pin @latest_allowable_version = latest_allowable_version @lock_ruby_version = lock_ruby_version end |
Instance Method Details
#gemspec_sources ⇒ Object
Can’t be a constant because some of these don’t exist in bundler 1.15, which Heroku uses, which causes an exception on boot.
33 34 35 36 37 38 |
# File 'lib/dependabot/bundler/update_checker/file_preparer.rb', line 33 def gemspec_sources [ ::Bundler::Source::Path, ::Bundler::Source::Gemspec ] end |
#prepared_dependency_files ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/dependabot/bundler/update_checker/file_preparer.rb', line 57 def prepared_dependency_files files = [] if gemfile files << DependencyFile.new( name: gemfile.name, content: gemfile_content_for_update_check(gemfile), directory: gemfile.directory ) end top_level_gemspecs.each do |gemspec| files << DependencyFile.new( name: gemspec.name, content: gemspec_content_for_update_check(gemspec), directory: gemspec.directory ) end path_gemspecs.each do |file| files << DependencyFile.new( name: file.name, content: sanitize_gemspec_content(file.content), directory: file.directory, support_file: file.support_file? ) end evaled_gemfiles.each do |file| files << DependencyFile.new( name: file.name, content: gemfile_content_for_update_check(file), directory: file.directory ) end # No editing required for lockfile or Ruby version file files += [ lockfile, ruby_version_file, tool_versions_file, *imported_ruby_files, *specification_files ].compact end |