Class: Dependabot::Helm::Version
- Inherits:
-
Version
- Object
- Version
- Dependabot::Helm::Version
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/helm/version.rb
Overview
In the special case of Java, the version string may also contain optional “update number” and “identifier” components. See www.oracle.com/java/technologies/javase/versioning-naming.html for a description of Java versions.
Constant Summary collapse
- HELM_VERSION_REGEX =
The regex has limits for the 0,255 and 1,255 repetitions to avoid infinite limits which makes codeql angry. A docker image cannot be longer than 255 characters anyways.
/^(?<prefix>[a-z._\-]{0,255})[_\-v]?(?<version>[^+]{1,255})(\+(?<digest>.+))?$/
Instance Attribute Summary collapse
-
#release_part ⇒ Object
readonly
Returns the value of attribute release_part.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
- #segments ⇒ Object
- #sort_criteria ⇒ Object
- #to_s ⇒ Object
- #to_semver ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Returns a new instance of Version.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dependabot/helm/version.rb', line 24 def initialize(version) parsed_version = version.to_s.match(HELM_VERSION_REGEX) release_part, update_part = T.must(T.must(parsed_version)[:version]).split("_", 2) # The numeric_version is needed here to validate the version string (ex: 20.9.0-alpine3.18) # when the call is made via Dependabot Api to convert the image version to semver. release_part = Dependabot::Docker::Tag.new( T.must(release_part).chomp(".").chomp("-").chomp("_") ).numeric_version @digest = T.let(T.must(parsed_version)[:digest], T.nilable(String)) @release_part = T.let(Dependabot::Version.new(T.must(release_part).tr("-", ".")), Dependabot::Version) @update_part = T.let( Dependabot::Version.new(update_part&.start_with?(/[0-9]/) ? update_part : 0), Dependabot::Version ) super(@release_part) end |
Instance Attribute Details
#release_part ⇒ Object (readonly)
Returns the value of attribute release_part.
85 86 87 |
# File 'lib/dependabot/helm/version.rb', line 85 def release_part @release_part end |
Class Method Details
.correct?(version) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dependabot/helm/version.rb', line 45 def self.correct?(version) return true if version.is_a?(Gem::Version) # We can't call new here because Gem::Version calls self.correct? in its initialize method # causing an infinite loop, so instead we check if the release_part of the version is correct parsed_version = version.to_s.match(HELM_VERSION_REGEX) return false if parsed_version.nil? release_part, = T.must(parsed_version[:version]).split("_", 2) release_part = Dependabot::Docker::Tag.new( T.must(release_part).chomp(".").chomp("-").chomp("_") ).numeric_version return false unless release_part super(release_part.to_s) rescue ArgumentError # if we can't instantiate a version, it can't be correct false end |
Instance Method Details
#<=>(other) ⇒ Object
88 89 90 |
# File 'lib/dependabot/helm/version.rb', line 88 def <=>(other) sort_criteria <=> other.sort_criteria end |
#segments ⇒ Object
71 72 73 |
# File 'lib/dependabot/helm/version.rb', line 71 def segments @release_part.segments end |
#sort_criteria ⇒ Object
93 94 95 |
# File 'lib/dependabot/helm/version.rb', line 93 def sort_criteria [@release_part, @update_part] end |
#to_s ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/dependabot/helm/version.rb', line 76 def to_s return nil if @release_part.nil? version_string = @release_part.to_s version_string += "+#{@digest}" unless @digest.nil? version_string end |
#to_semver ⇒ Object
66 67 68 |
# File 'lib/dependabot/helm/version.rb', line 66 def to_semver @release_part.to_semver end |