Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Detected Version to Base Version Manager and Update Ecosystem Package Managers and Languages #11190

Merged
merged 18 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bundler/lib/dependabot/bundler/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ 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(
name: LANGUAGE,
version: Version.new(raw_version),
requirement: requirement)
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions bundler/lib/dependabot/bundler/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
end
def initialize(raw_version, requirement = nil)
super(
PACKAGE_MANAGER,
Version.new(raw_version),
DEPRECATED_BUNDLER_VERSIONS,
SUPPORTED_BUNDLER_VERSIONS,
requirement,
name: PACKAGE_MANAGER,
version: Version.new(raw_version),
deprecated_versions: DEPRECATED_BUNDLER_VERSIONS,
supported_versions: SUPPORTED_BUNDLER_VERSIONS,
requirement: requirement,
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions cargo/lib/dependabot/cargo/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Language < Dependabot::Ecosystem::VersionManager
sig { params(raw_version: String).void }
def initialize(raw_version)
super(
LANGUAGE,
Version.new(raw_version)
name: LANGUAGE,
version: Version.new(raw_version)
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions cargo/lib/dependabot/cargo/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class PackageManager < Dependabot::Ecosystem::VersionManager
sig { params(raw_version: String).void }
def initialize(raw_version)
super(
PACKAGE_MANAGER,
Version.new(raw_version),
DEPRECATED_CARGO_VERSIONS,
SUPPORTED_CARGO_VERSIONS
name: PACKAGE_MANAGER,
version: Version.new(raw_version),
deprecated_versions: DEPRECATED_CARGO_VERSIONS,
supported_versions: SUPPORTED_CARGO_VERSIONS
)
end

Expand Down
46 changes: 33 additions & 13 deletions common/lib/dependabot/ecosystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,38 @@ 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.
# @example
# VersionManager.new("bundler", "2.1.4", nil)
# VersionManager.new(
# name: "bundler",
# version: Version.new("2.1.4"),
# requirement: nil
# )
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(
name,
version,
deprecated_versions = [],
supported_versions = [],
requirement = nil
name:,
detected_version: nil,
version: nil,
deprecated_versions: [],
supported_versions: [],
requirement: nil
)
@name = T.let(name, String)
@version = T.let(version, Dependabot::Version)
@detected_version = T.let(detected_version || version, T.nilable(Dependabot::Version))
@version = T.let(version, T.nilable(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,10 +60,16 @@ def initialize(
sig { returns(String) }
attr_reader :name

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

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

# Returns an array of deprecated versions of the package manager.
Expand All @@ -82,35 +96,41 @@ def initialize(
# deprecated? #=> true
sig { returns(T::Boolean) }
def deprecated?
return false unless detected_version

# 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.
# @example
# unsupported? #=> false
sig { returns(T::Boolean) }
def unsupported?
return false unless detected_version

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.
# If the version is unsupported, it raises a ToolVersionNotSupported error.
sig { void }
def raise_if_unsupported!
return unless detected_version

return unless unsupported?

# Example: v2.*, v3.*
supported_versions_message = supported_versions.map { |v| "v#{v}.*" }.join(", ")

raise ToolVersionNotSupported.new(
name,
version.to_s,
detected_version.to_s,
supported_versions_message
)
end
Expand Down
2 changes: 1 addition & 1 deletion common/lib/dependabot/notices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def self.generate_pm_deprecation_notice(package_manager)
)
notice_type = "#{package_manager.name}_deprecated_warn"
title = "Package manager deprecation notice"
description = "Dependabot will stop supporting `#{package_manager.name} v#{package_manager.version}`!"
description = "Dependabot will stop supporting `#{package_manager.name} v#{package_manager.detected_version}`!"

## Add the supported versions to the description
description += "\n\n#{supported_versions_description}\n" unless supported_versions_description.empty?
Expand Down
43 changes: 29 additions & 14 deletions common/spec/dependabot/ecosystem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,44 @@
let(:deprecated_versions) { [Dependabot::Version.new("1")] }
let(:requirement) { TestRequirement.new(">= 1.0") }

let(:package_manager_detected_version) { "1.0.0" }
let(:package_manager_raw_version) { "1.0.0" }
let(:language_detected_version) { "3.0.0" }
let(:language_raw_version) { "3.0.0" }

let(:package_manager) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def initialize(raw_version, deprecated_versions, supported_versions, requirement)
def initialize(detected_version, raw_version, deprecated_versions, supported_versions, requirement)
super(
"bundler", # name
Dependabot::Version.new(raw_version), # version
deprecated_versions, # deprecated_versions
supported_versions, # supported_versions
requirement # requirement
name: "bundler", # name
detected_version: Dependabot::Version.new(detected_version), # version
version: Dependabot::Version.new(raw_version), # version
deprecated_versions: deprecated_versions, # deprecated_versions
supported_versions: supported_versions, # supported_versions
requirement: requirement # requirement
)
end
end.new(package_manager_raw_version, deprecated_versions, supported_versions, requirement)
end.new(
package_manager_detected_version,
package_manager_raw_version,
deprecated_versions,
supported_versions,
requirement
)
end

let(:language) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def initialize(raw_version)
def initialize(detected_version, raw_version)
super(
"ruby", # name
Dependabot::Version.new(raw_version), # version
[], # deprecated_versions
[], # supported_versions
nil # requirement
name: "ruby", # name
detected_version: Dependabot::Version.new(detected_version), # version
version: Dependabot::Version.new(raw_version), # version
deprecated_versions: [], # deprecated_versions
supported_versions: [], # supported_versions
)
end
end.new(language_raw_version)
end.new(language_detected_version, language_raw_version)
end

describe "#initialize" do
Expand All @@ -56,6 +65,7 @@ def initialize(raw_version)

describe "#deprecated?" do
context "when the package manager version is deprecated" do
let(:package_manager_detected_version) { "1" }
let(:package_manager_raw_version) { "1" }

it "returns true" do
Expand All @@ -65,6 +75,7 @@ def initialize(raw_version)
end

context "when the package manager version is not deprecated" do
let(:package_manager_detected_version) { "2.0.0" }
let(:package_manager_raw_version) { "2.0.0" }

it "returns false" do
Expand All @@ -76,6 +87,7 @@ def initialize(raw_version)

describe "#unsupported?" do
context "when the package manager version is unsupported" do
let(:package_manager_detected_version) { "0.8.0" }
let(:package_manager_raw_version) { "0.8.0" }

it "returns true" do
Expand All @@ -85,6 +97,7 @@ def initialize(raw_version)
end

context "when the package manager version is supported" do
let(:package_manager_detected_version) { "2.0.0" }
let(:package_manager_raw_version) { "2.0.0" }

it "returns false" do
Expand All @@ -96,6 +109,7 @@ def initialize(raw_version)

describe "#raise_if_unsupported!" do
context "when the package manager version is unsupported" do
let(:package_manager_detected_version) { "0.8.0" }
let(:package_manager_raw_version) { "0.8.0" }

it "raises a ToolVersionNotSupported error" do
Expand All @@ -105,6 +119,7 @@ def initialize(raw_version)
end

context "when the package manager version is supported" do
let(:package_manager_detected_version) { "2.0.0" }
let(:package_manager_raw_version) { "2.0.0" }

it "does not raise an error" do
Expand Down
8 changes: 4 additions & 4 deletions common/spec/dependabot/file_parsers/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
def initialize
raw_version = "1.0.0"
super(
"bundler", # name
Dependabot::Version.new(raw_version), # version
[Dependabot::Version.new("1.0.0")], # deprecated_versions
[Dependabot::Version.new("1.1.0"), Dependabot::Version.new("2.0.0")] # supported_versions
name: "bundler", # name
version: Dependabot::Version.new(raw_version), # version
deprecated_versions: [Dependabot::Version.new("1.0.0")], # deprecated_versions
supported_versions: [Dependabot::Version.new("1.1.0"), Dependabot::Version.new("2.0.0")] # supported_versions
)
end

Expand Down
14 changes: 8 additions & 6 deletions common/spec/dependabot/notices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

# A stub package manager for testing purposes.
class StubPackageManager < Dependabot::Ecosystem::VersionManager
def initialize(name:, version:, deprecated_versions: [], supported_versions: [],
def initialize(name:, detected_version:, raw_version:, deprecated_versions: [], supported_versions: [],
support_later_versions: false)
@support_later_versions = support_later_versions
super(
name,
Dependabot::Version.new(version),
deprecated_versions,
supported_versions
name: name,
detected_version: Dependabot::Version.new(detected_version),
version: Dependabot::Version.new(raw_version),
deprecated_versions: deprecated_versions,
supported_versions: supported_versions
)
end

Expand Down Expand Up @@ -113,7 +114,8 @@ def support_later_versions?
let(:package_manager) do
StubPackageManager.new(
name: "bundler",
version: Dependabot::Version.new("1"),
detected_version: Dependabot::Version.new("1"),
raw_version: Dependabot::Version.new("1.0.0"),
deprecated_versions: [Dependabot::Version.new("1")],
supported_versions: [Dependabot::Version.new("2"), Dependabot::Version.new("3")]
)
Expand Down
28 changes: 18 additions & 10 deletions common/spec/dependabot/version_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
let(:concrete_class) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def initialize
detected_version = "1.0.0"
raw_version = "1.0.0"
super(
"bundler", # name
Dependabot::Version.new(raw_version), # version
[Dependabot::Version.new("1")], # deprecated_versions
[Dependabot::Version.new("1"), Dependabot::Version.new("2")] # supported_versions
name: "bundler", # name
detected_version: Dependabot::Version.new(detected_version), # version
version: Dependabot::Version.new(raw_version), # version
deprecated_versions: [Dependabot::Version.new("1")], # deprecated_versions
supported_versions: [Dependabot::Version.new("1"), Dependabot::Version.new("2")] # supported_versions
)
end

Expand All @@ -26,10 +28,12 @@ def support_later_versions?
let(:default_concrete_class) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def initialize
detected_version = "1.0.0"
raw_version = "1.0.0"
super(
"bundler", # name
Dependabot::Version.new(raw_version)
name: "bundler", # name
detected_version: Dependabot::Version.new(detected_version),
version: Dependabot::Version.new(raw_version)
)
end
end
Expand Down Expand Up @@ -90,10 +94,12 @@ def initialize
end

context "when version is unsupported" do
let(:version) { Dependabot::Version.new("0.9.0") }
let(:detected_version) { Dependabot::Version.new("0.9") }
let(:raw_version) { Dependabot::Version.new("0.9.0") }

it "returns false as unsupported takes precedence" do
package_manager.instance_variable_set(:@version, version)
package_manager.instance_variable_set(:@detected_version, detected_version)
package_manager.instance_variable_set(:@version, raw_version)
package_manager.instance_variable_set(:@supported_versions,
[Dependabot::Version.new("1"), Dependabot::Version.new("2")])
expect(package_manager.deprecated?).to be false
Expand All @@ -103,10 +109,12 @@ def initialize

describe "#unsupported?" do
context "when version is unsupported" do
let(:version) { Dependabot::Version.new("0.9.0") }
let(:detected_version) { Dependabot::Version.new("0.9") }
let(:raw_version) { Dependabot::Version.new("0.9.0") }

it "returns true" do
package_manager.instance_variable_set(:@version, version)
package_manager.instance_variable_set(:@detected_version, detected_version)
package_manager.instance_variable_set(:@version, raw_version)
package_manager.instance_variable_set(:@supported_versions,
[Dependabot::Version.new("1"), Dependabot::Version.new("2")])
expect(package_manager.unsupported?).to be true
Expand Down
Loading
Loading