Skip to content

Commit

Permalink
seperate raw_version and detected_version for all package managers
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Dec 24, 2024
1 parent c0b00ef commit 512e9c2
Show file tree
Hide file tree
Showing 34 changed files with 204 additions and 47 deletions.
4 changes: 2 additions & 2 deletions bundler/lib/dependabot/bundler/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def ecosystem

sig { returns(Ecosystem::VersionManager) }
def package_manager
@package_manager ||= PackageManager.new(bundler_raw_version, package_manager_requirement)
@package_manager ||= PackageManager.new(bundler_version, bundler_raw_version, package_manager_requirement)
end

def package_manager_requirement
Expand Down Expand Up @@ -355,7 +355,7 @@ def imported_ruby_files
def bundler_raw_version
return bundler_raw_version if defined?(@bundler_raw_version)

package_manager = PackageManager.new(bundler_version)
package_manager = PackageManager.new(bundler_version, "")

# If the selected version is unsupported, an unsupported error will be raised,
# so there’s no need to attempt retrieving the raw version.
Expand Down
9 changes: 8 additions & 1 deletion bundler/lib/dependabot/bundler/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ class Language < Dependabot::Ecosystem::VersionManager

sig { params(raw_version: String, requirement: T.nilable(Requirement)).void }
def initialize(raw_version, requirement = nil)
super(LANGUAGE, Version.new(raw_version), [], [], requirement)
super(
LANGUAGE,
Version.new(""),
Version.new(raw_version),
[],
[],
requirement
)
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions bundler/lib/dependabot/bundler/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ class PackageManager < Dependabot::Ecosystem::VersionManager

sig do
params(
raw_version: String,
detected_version: String,
raw_version: T.nilable(String),
requirement: T.nilable(Requirement)
).void
end
def initialize(raw_version, requirement = nil)
def initialize(detected_version, raw_version, requirement = nil)
super(
PACKAGE_MANAGER,
Version.new(detected_version),
Version.new(raw_version),
DEPRECATED_BUNDLER_VERSIONS,
SUPPORTED_BUNDLER_VERSIONS,
Expand Down
1 change: 1 addition & 0 deletions cargo/lib/dependabot/cargo/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Language < Dependabot::Ecosystem::VersionManager
def initialize(raw_version)
super(
LANGUAGE,
Version.new(""),
Version.new(raw_version)
)
end
Expand Down
1 change: 1 addition & 0 deletions cargo/lib/dependabot/cargo/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
def initialize(raw_version)
super(
PACKAGE_MANAGER,
Version.new(""),
Version.new(raw_version),
DEPRECATED_CARGO_VERSIONS,
SUPPORTED_CARGO_VERSIONS
Expand Down
26 changes: 18 additions & 8 deletions common/lib/dependabot/ecosystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class VersionManager
abstract!
# Initialize version information for a package manager or language.
# @param name [String] the name of the package manager or language (e.g., "bundler", "ruby").
# @param version [Dependabot::Version] the parsed current version.
# @param detected_version [Dependabot::Version] the detected version of the package manager or language.
# @param version [Dependabot::Version] the version dependabots run on.
# @param deprecated_versions [Array<Dependabot::Version>] an array of deprecated versions.
# @param supported_versions [Array<Dependabot::Version>] an array of supported versions.
# @param requirement [Dependabot::Requirement] an array of requirements.
Expand All @@ -26,21 +27,24 @@ class VersionManager
sig do
params(
name: String,
version: Dependabot::Version,
detected_version: T.nilable(Dependabot::Version),
version: T.nilable(Dependabot::Version),
deprecated_versions: T::Array[Dependabot::Version],
supported_versions: T::Array[Dependabot::Version],
requirement: T.nilable(Dependabot::Requirement)
).void
end
def initialize(
def initialize( # rubocop:disable Metrics/ParameterLists
name,
version,
detected_version = Dependabot::Version.new(""),
version = Dependabot::Version.new(""),
deprecated_versions = [],
supported_versions = [],
requirement = nil
)
@name = T.let(name, String)
@version = T.let(version, Dependabot::Version)
@detected_version = T.let(T.must(detected_version), Dependabot::Version)
@version = T.let(T.must(version), Dependabot::Version)
@deprecated_versions = T.let(deprecated_versions, T::Array[Dependabot::Version])
@supported_versions = T.let(supported_versions, T::Array[Dependabot::Version])
@requirement = T.let(requirement, T.nilable(Dependabot::Requirement))
Expand All @@ -52,6 +56,12 @@ def initialize(
sig { returns(String) }
attr_reader :name

# The current version of the package manager or language.
# @example
# version #=> Dependabot::Version.new("2")
sig { returns(Dependabot::Version) }
attr_reader :detected_version

# The current version of the package manager or language.
# @example
# version #=> Dependabot::Version.new("2.1.4")
Expand Down Expand Up @@ -85,7 +95,7 @@ def deprecated?
# If the version is unsupported, the unsupported error is getting raised separately.
return false if unsupported?

deprecated_versions.include?(version)
deprecated_versions.include?(detected_version)
end

# Checks if the current version is unsupported.
Expand All @@ -96,7 +106,7 @@ def unsupported?
return false if supported_versions.empty?

# Check if the version is not supported
supported_versions.all? { |supported| supported > version }
supported_versions.all? { |supported| supported > detected_version }
end

# Raises an error if the current package manager or language version is unsupported.
Expand All @@ -110,7 +120,7 @@ def raise_if_unsupported!

raise ToolVersionNotSupported.new(
name,
version.to_s,
detected_version.to_s,
supported_versions_message
)
end
Expand Down
8 changes: 8 additions & 0 deletions common/spec/dependabot/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@

it { is_expected.to eq(["> #{version_string}, < 1.3"]) }
end

context "when the version string is empty" do
let(:version_string) { "" }

it "is equal `0" do
expect(version.to_s).to eq("0")
end
end
end
4 changes: 3 additions & 1 deletion composer/lib/dependabot/composer/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ def ecosystem
def package_manager
if composer_version == Helpers::V1
return PackageManager.new(
composer_version,
composer_version
)
end
PackageManager.new(
env_versions[:composer] || composer_version
composer_version,
env_versions[:composer]
)
end

Expand Down
1 change: 1 addition & 0 deletions composer/lib/dependabot/composer/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Language < Dependabot::Ecosystem::VersionManager
def initialize(raw_version, requirement: nil)
super(
NAME,
Version.new(""),
Version.new(raw_version),
[],
[],
Expand Down
10 changes: 8 additions & 2 deletions composer/lib/dependabot/composer/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
# DEPRECATED_COMPOSER_VERSIONS = T.let([Version.new("1")].freeze, T::Array[Dependabot::Version])
DEPRECATED_COMPOSER_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])

sig { params(raw_version: String).void }
def initialize(raw_version)
sig do
params(
detected_version: String,
raw_version: T.nilable(String)
).void
end
def initialize(detected_version, raw_version)
super(
NAME,
Version.new(detected_version),
Version.new(raw_version),
DEPRECATED_COMPOSER_VERSIONS,
SUPPORTED_COMPOSER_VERSIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
def initialize(raw_version)
super(
PACKAGE_MANAGER,
Version.new(""),
Version.new(raw_version),
DEPRECATED_DEVCONTAINER_VERSIONS,
SUPPORTED_DEVCONTAINER_VERSIONS
Expand Down
9 changes: 8 additions & 1 deletion elm/lib/dependabot/elm/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ class Language < Dependabot::Ecosystem::VersionManager

sig { params(raw_version: String, requirement: T.nilable(Requirement)).void }
def initialize(raw_version, requirement = nil)
super(LANGUAGE, Version.new(raw_version), [], [], requirement)
super(
LANGUAGE,
Version.new(""),
Version.new(raw_version),
[],
[],
requirement
)
end

sig { returns(T::Boolean) }
Expand Down
1 change: 1 addition & 0 deletions elm/lib/dependabot/elm/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
def initialize(raw_version, requirement = nil)
super(
PACKAGE_MANAGER,
Version.new(""),
Version.new(raw_version),
DEPRECATED_ELM_VERSIONS,
SUPPORTED_ELM_VERSIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
def initialize(raw_version)
super(
PACKAGE_MANAGER,
Version.new(""),
Version.new(raw_version),
DEPRECATED_GIT_VERSIONS,
SUPPORTED_GIT_VERSIONS
Expand Down
1 change: 1 addition & 0 deletions go_modules/lib/dependabot/go_modules/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Language < Dependabot::Ecosystem::VersionManager
def initialize(raw_version)
super(
LANGUAGE,
Version.new(""),
Version.new(raw_version)
)
end
Expand Down
1 change: 1 addition & 0 deletions go_modules/lib/dependabot/go_modules/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
def initialize(raw_version)
super(
PACKAGE_MANAGER,
Version.new(""),
Version.new(raw_version),
DEPRECATED_GO_VERSIONS,
SUPPORTED_GO_VERSIONS
Expand Down
1 change: 1 addition & 0 deletions gradle/lib/dependabot/gradle/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Language < Dependabot::Ecosystem::VersionManager
def initialize(raw_version)
super(
LANGUAGE,
Version.new(""),
Version.new(raw_version)
)
end
Expand Down
1 change: 1 addition & 0 deletions gradle/lib/dependabot/gradle/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
def initialize(raw_version)
super(
PACKAGE_MANAGER,
Version.new(""),
Version.new(raw_version),
DEPRECATED_GRADLE_VERSIONS,
SUPPORTED_GRADLE_VERSIONS
Expand Down
6 changes: 5 additions & 1 deletion hex/lib/dependabot/hex/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ class Language < Dependabot::Ecosystem::VersionManager

sig { params(raw_version: String).void }
def initialize(raw_version)
super(LANGUAGE, Version.new(raw_version))
super(
LANGUAGE,
Version.new(""),
Version.new(raw_version)
)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions hex/lib/dependabot/hex/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
def initialize(raw_version)
super(
PACKAGE_MANAGER,
Version.new(""),
Version.new(raw_version),
DEPRECATED_HEX_VERSIONS,
SUPPORTED_HEX_VERSIONS
Expand Down
4 changes: 2 additions & 2 deletions maven/lib/dependabot/maven/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ def ecosystem
sig { returns(Ecosystem::VersionManager) }
def package_manager
@package_manager ||= T.let(
PackageManager.new("NOT-AVAILABLE"),
PackageManager.new("", ""),
T.nilable(Dependabot::Maven::PackageManager)
)
end

sig { returns(T.nilable(Ecosystem::VersionManager)) }
def language
@language ||= T.let(begin
Language.new("NOT-AVAILABLE")
Language.new("", "")
end, T.nilable(Dependabot::Maven::Language))
end

Expand Down
13 changes: 11 additions & 2 deletions maven/lib/dependabot/maven/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ module Maven
class Language < Dependabot::Ecosystem::VersionManager
extend T::Sig

sig { params(raw_version: String).void }
def initialize(raw_version)
sig do
params(
detected_version: String,
raw_version: String
).void
end
def initialize(
detected_version,
raw_version
)
super(
LANGUAGE,
Version.new(detected_version),
Version.new(raw_version)
)
end
Expand Down
4 changes: 3 additions & 1 deletion maven/lib/dependabot/maven/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ class PackageManager < Dependabot::Ecosystem::VersionManager

sig do
params(
detected_version: String,
raw_version: String,
requirement: T.nilable(Requirement)
).void
end
def initialize(raw_version, requirement = nil)
def initialize(detected_version, raw_version, requirement = nil)
super(
PACKAGE_MANAGER,
Version.new(detected_version),
Version.new(raw_version),
DEPRECATED_MAVEN_VERSIONS,
SUPPORTED_MAVEN_VERSIONS,
Expand Down
Loading

0 comments on commit 512e9c2

Please sign in to comment.