Class: Dependabot::Uv::FileUpdater::RequirementReplacer
- Inherits:
-
Object
- Object
- Dependabot::Uv::FileUpdater::RequirementReplacer
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/uv/file_updater/requirement_replacer.rb
Constant Summary collapse
- PACKAGE_NOT_FOUND_ERROR =
"PackageNotFoundError"- CERTIFICATE_VERIFY_FAILED =
/CERTIFICATE_VERIFY_FAILED/
Instance Method Summary collapse
-
#initialize(content:, dependency_name:, old_requirement:, new_requirement:, new_hash_version: nil, index_urls: nil) ⇒ RequirementReplacer
constructor
A new instance of RequirementReplacer.
- #requirement_error_handler(error) ⇒ Object
- #updated_content ⇒ Object
Constructor Details
#initialize(content:, dependency_name:, old_requirement:, new_requirement:, new_hash_version: nil, index_urls: nil) ⇒ RequirementReplacer
Returns a new instance of RequirementReplacer.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dependabot/uv/file_updater/requirement_replacer.rb', line 33 def initialize( content:, dependency_name:, old_requirement:, new_requirement:, new_hash_version: nil, index_urls: nil ) @content = T.let(content, String) @dependency_name = T.let(normalise(dependency_name), String) @old_requirement = T.let(old_requirement, T.nilable(String)) @new_requirement = T.let(new_requirement, T.nilable(String)) @new_hash_version = T.let(new_hash_version, T.nilable(String)) @index_urls = T.let(index_urls, T.nilable(T::Array[T.nilable(String)])) end |
Instance Method Details
#requirement_error_handler(error) ⇒ Object
246 247 248 249 250 251 252 253 |
# File 'lib/dependabot/uv/file_updater/requirement_replacer.rb', line 246 def requirement_error_handler(error) Dependabot.logger.warn(error.) return unless error..match?(CERTIFICATE_VERIFY_FAILED) msg = "Error resolving dependency." raise DependencyFileNotResolvable, msg end |
#updated_content ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dependabot/uv/file_updater/requirement_replacer.rb', line 50 def updated_content updated_content = content.gsub(original_declaration_replacement_regex) do |mtch| # If the "declaration" is setting an option (e.g., no-binary) # ignore it, since it isn't actually a declaration next mtch if Regexp.last_match&.pre_match&.match?(/--.*\z/) updated_dependency_declaration_string end raise "Expected content to change!" if old_requirement != new_requirement && content == updated_content updated_content end |