Class: Dependabot::Helm::UpdateChecker::RequirementsUpdater

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/helm/update_checker/requirements_updater.rb

Constant Summary collapse

VERSION_REGEX =

Possessive quantifiers (++) keep these linear on pathological input (no catastrophic/polynomial backtracking) while matching identically to the greedy forms for real version constraints. The trailing group consumes an optional '+<build metadata/digest>' suffix so rewrites replace it wholesale instead of leaving a stale suffix behind (e.g. "1.2.3+old" -> "1.5.0", not "1.5.0+old").

/[0-9]++(?:\.[A-Za-z0-9\-_]++)*+(?:\+[A-Za-z0-9\-_.]++)?/
SEPARATOR =
/(?<=[a-zA-Z0-9*])[\s|]++(?![\s|-])/
UPPER_COMPARATOR_REGEX =

The version attached to an upper comparator (</<=) or a hyphen endpoint — the bound that widening moves.

/<=?\s*(#{VERSION_REGEX})/
HYPHEN_UPPER_REGEX =
/\s-\s+(#{VERSION_REGEX})/
ALLOWED_UPDATE_STRATEGIES =
T.let(
  [
    RequirementsUpdateStrategy::LockfileOnly,
    RequirementsUpdateStrategy::WidenRanges,
    RequirementsUpdateStrategy::BumpVersions,
    RequirementsUpdateStrategy::BumpVersionsIfNecessary
  ].freeze,
  T::Array[Dependabot::RequirementsUpdateStrategy]
)

Instance Method Summary collapse

Constructor Details

#initialize(requirements:, update_strategy:, latest_resolvable_version:) ⇒ RequirementsUpdater

Returns a new instance of RequirementsUpdater.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dependabot/helm/update_checker/requirements_updater.rb', line 54

def initialize(requirements:, update_strategy:, latest_resolvable_version:)
  @requirements = requirements
  @update_strategy = update_strategy

  check_update_strategy

  return unless latest_resolvable_version

  @latest_resolvable_version = T.let(
    version_class.new(latest_resolvable_version),
    Dependabot::Version
  )
end

Instance Method Details

#updated_requirementsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dependabot/helm/update_checker/requirements_updater.rb', line 69

def updated_requirements
  return requirements if update_strategy.lockfile_only?

  requirements.map do |req|
    next req unless latest_resolvable_version
    next req unless req[:requirement]
    # Leave dist-tags / non-numeric leading tokens untouched.
    next req if req[:requirement].match?(/^([A-Za-uw-z]|v[^\d])/)

    case update_strategy
    when RequirementsUpdateStrategy::WidenRanges then widen_requirement(req)
    when RequirementsUpdateStrategy::BumpVersions then update_version_requirement(req)
    when RequirementsUpdateStrategy::BumpVersionsIfNecessary
      update_version_requirement_if_needed(req)
    else raise "Unexpected update strategy: #{update_strategy}"
    end
  end
end