Skip to content

Commit

Permalink
update package manager to use version manager in ecosystem
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Oct 23, 2024
1 parent fe66a8f commit a8bc22d
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion bundler/lib/dependabot/bundler/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def parse
dependency_set.dependencies
end

sig { returns(PackageManagerBase) }
sig { returns(Ecosystem::VersionManager) }
def package_manager
PackageManager.new(bundler_version)
end
Expand Down
34 changes: 17 additions & 17 deletions common/lib/dependabot/ecosystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class VersionManager
abstract!
# Initialize version information with optional requirement
# @param name [String] the name of the package manager or language (e.g., "bundler", "ruby").
# @param raw_current_version [String] the raw current version of the package manager or language.
# @param current_version [Dependabot::Version] the parsed current version.
# @param raw_version [String] the raw current version of the package manager or language.
# @param version [Dependabot::Version] the parsed current version.
# @param deprecated_versions [Array<Dependabot::Version>] an array of deprecated versions.
# @param supported_versions [Array<Dependabot::Version>] an array of supported versions.
# @param requirement [T.nilable(Requirement)] the version requirements, optional.
Expand All @@ -24,24 +24,24 @@ class VersionManager
sig do
params(
name: String,
raw_current_version: String,
current_version: Dependabot::Version,
raw_version: String,
version: Dependabot::Version,
deprecated_versions: T::Array[Dependabot::Version],
supported_versions: T::Array[Dependabot::Version],
requirement: T.nilable(Requirement)
).void
end
def initialize( # rubocop:disable Metrics/ParameterLists
name,
raw_current_version,
current_version,
raw_version,
version,
deprecated_versions = [],
supported_versions = [],
requirement = nil
)
@name = T.let(name, String)
@raw_current_version = T.let(raw_current_version, String)
@current_version = T.let(current_version, Dependabot::Version)
@raw_version = T.let(raw_version, String)
@version = T.let(version, Dependabot::Version)
@requirement = T.let(requirement, T.nilable(Requirement))

@deprecated_versions = T.let(deprecated_versions, T::Array[Dependabot::Version])
Expand All @@ -56,15 +56,15 @@ def initialize( # rubocop:disable Metrics/ParameterLists

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

# The raw current version of the package manager or language as a string.
# @example
# version_information.raw_current_version #=> "2.1.4"
# version_information.raw_version #=> "2.1.4"
sig { returns(String) }
attr_reader :raw_current_version
attr_reader :raw_version

# The version requirements (optional).
# @example
Expand All @@ -91,15 +91,15 @@ def deprecated?
# If the version is unsupported, the unsupported error is getting raised separately.
return false if unsupported?

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

# Checks if the current version is unsupported.
# @example
# package_manager.unsupported? #=> false
sig { returns(T::Boolean) }
def unsupported?
supported_versions.empty? || supported_versions.all? { |v| v > current_version }
supported_versions.empty? || supported_versions.all? { |v| v > version }
end

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

raise ToolVersionNotSupported.new(
name,
current_version.to_s,
version.to_s,
supported_versions_message
)
end
Expand Down Expand Up @@ -190,8 +190,8 @@ class Language

# Initialize with mandatory ecosystem and optional language information.
# @param ecosystem [String] the name of the ecosystem (e.g., "bundler", "npm_and_yarn").
# @param package_managers [PackageManagerBase] the package manager
# @param language [T.nilable(Ecosystem::VersionInformation)] optional language version information.
# @param package_managers [VersionManager] the package manager
# @param language [T.nilable(VersionManager)] optional language version information.
sig do
params(
ecosystem: String,
Expand Down
4 changes: 2 additions & 2 deletions common/lib/dependabot/file_parsers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require "sorbet-runtime"
require "dependabot/credential"
require "dependabot/package_manager"
require "dependabot/ecosystem"

module Dependabot
module FileParsers
Expand Down Expand Up @@ -54,7 +54,7 @@ def initialize(dependency_files:, source:, repo_contents_path: nil,
sig { abstract.returns(T::Array[Dependabot::Dependency]) }
def parse; end

sig { returns(T.nilable(PackageManagerBase)) }
sig { returns(T.nilable(Ecosystem::VersionManager)) }
def package_manager
nil
end
Expand Down
6 changes: 3 additions & 3 deletions common/lib/dependabot/notices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

require "sorbet-runtime"
require "dependabot/package_manager"
require "dependabot/ecosystem"

module Dependabot
class Notice
Expand Down Expand Up @@ -95,11 +95,11 @@ def self.generate_supported_versions_description(supported_versions, support_lat
end

# Generates a deprecation notice for the given package manager.
# @param package_manager [PackageManagerBase] The package manager object.
# @param package_manager [VersionManager] The package manager object.
# @return [Notice, nil] The generated deprecation notice or nil if the package manager is not deprecated.
sig do
params(
package_manager: PackageManagerBase
package_manager: Ecosystem::VersionManager
).returns(T.nilable(Notice))
end
def self.generate_pm_deprecation_notice(package_manager)
Expand Down
6 changes: 3 additions & 3 deletions common/spec/dependabot/file_parsers/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
let(:files) { [gemfile] }

let(:concrete_package_manager_class) do
Class.new(Dependabot::PackageManagerBase) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def name
"bundler"
end
Expand Down Expand Up @@ -117,8 +117,8 @@ def support_later_versions?
context "when called on a concrete class" do
let(:package_manager_instance) { concrete_package_manager_class.new }

it "returns an instance of PackageManagerBase" do
expect(parser_instance.package_manager).to be_a(Dependabot::PackageManagerBase)
it "returns an instance of Ecosystem::VersionManager" do
expect(parser_instance.package_manager).to be_a(Dependabot::Ecosystem::VersionManager)
end

it "returns the correct package manager details" do
Expand Down
4 changes: 2 additions & 2 deletions common/spec/dependabot/notices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

require "dependabot/version"
require "dependabot/experiments"
require "dependabot/package_manager"
require "dependabot/ecosystem"
require "dependabot/notices"

# A stub package manager for testing purposes.
class StubPackageManager < Dependabot::PackageManagerBase
class StubPackageManager < Dependabot::Ecosystem::VersionManager
def initialize(name:, version:, deprecated_versions: [], unsupported_versions: [], supported_versions: [],
support_later_versions: false)
@name = name
Expand Down
8 changes: 4 additions & 4 deletions common/spec/dependabot/package_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# frozen_string_literal: true

require "spec_helper"
require "dependabot/package_manager"
require "dependabot/ecosystem"

RSpec.describe Dependabot::PackageManagerBase do # rubocop:disable RSpec/FilePath,RSpec/SpecFilePathFormat
RSpec.describe Dependabot::Ecosystem::VersionManager do # rubocop:disable RSpec/FilePath,RSpec/SpecFilePathFormat
let(:concrete_class) do
Class.new(Dependabot::PackageManagerBase) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def name
"bundler"
end
Expand Down Expand Up @@ -48,7 +48,7 @@ def support_later_versions?
end

let(:default_concrete_class) do
Class.new(Dependabot::PackageManagerBase) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def name
"bundler"
end
Expand Down
2 changes: 1 addition & 1 deletion composer/lib/dependabot/composer/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse
dependency_set.dependencies
end

sig { returns(PackageManagerBase) }
sig { returns(Ecosystem::VersionManager) }
def package_manager
PackageManager.new(composer_version)
end
Expand Down
4 changes: 2 additions & 2 deletions silent/lib/dependabot/silent/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "dependabot/dependency"
require "dependabot/file_parsers"
require "dependabot/file_parsers/base"
require "dependabot/package_manager"
require "dependabot/ecosystem"
require "dependabot/silent/package_manager"
require "sorbet-runtime"

Expand All @@ -28,7 +28,7 @@ def parse
raise Dependabot::DependencyFileNotParseable, T.must(dependency_files.first).path
end

sig { returns(Dependabot::PackageManagerBase) }
sig { returns(Dependabot::Ecosystem::VersionManager) }
def package_manager
meta_data = JSON.parse(manifest_content)["silent"]
silent_version = if meta_data.nil?
Expand Down
4 changes: 2 additions & 2 deletions silent/lib/dependabot/silent/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require "sorbet-runtime"
require "dependabot/silent/version"
require "dependabot/package_manager"
require "dependabot/ecosystem"

module Dependabot
module Silent
Expand All @@ -12,7 +12,7 @@ module Silent
SUPPORTED_SILENT_VERSIONS = T.let([Version.new("2")].freeze, T::Array[Dependabot::Version])
DEPRECATED_SILENT_VERSIONS = T.let([Version.new("1")].freeze, T::Array[Dependabot::Version])

class PackageManager < PackageManagerBase
class PackageManager < Ecosystem::VersionManager
extend T::Sig

sig { params(version: T.any(String, Dependabot::Version)).void }
Expand Down
4 changes: 2 additions & 2 deletions updater/lib/dependabot/dependency_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def dependencies
T.must(@dependencies[@current_directory])
end

sig { returns(T.nilable(Dependabot::PackageManagerBase)) }
sig { returns(T.nilable(Dependabot::Ecosystem::VersionManager)) }
def package_manager
@package_manager[@current_directory]
end
Expand Down Expand Up @@ -181,7 +181,7 @@ def initialize(job:, base_commit_sha:, dependency_files:) # rubocop:disable Metr
@current_directory = T.let("", String)

@dependencies = T.let({}, T::Hash[String, T::Array[Dependabot::Dependency]])
@package_manager = T.let({}, T::Hash[String, T.nilable(Dependabot::PackageManagerBase)])
@package_manager = T.let({}, T::Hash[String, T.nilable(Dependabot::Ecosystem::VersionManager)])
@notices = T.let({}, T::Hash[String, T::Array[Dependabot::Notice]])

directories.each do |dir|
Expand Down
8 changes: 4 additions & 4 deletions updater/lib/dependabot/notices_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require "sorbet-runtime"
require "dependabot/notices"
require "dependabot/package_manager"
require "dependabot/ecosystem"

# This module extracts helpers for notice generations that can be used
# for showing notices in logs, pr messages and alert ui page.
Expand All @@ -20,7 +20,7 @@ module NoticesHelpers
sig do
params(
notices: T::Array[Dependabot::Notice],
package_manager: T.nilable(PackageManagerBase)
package_manager: T.nilable(Ecosystem::VersionManager)
)
.void
end
Expand Down Expand Up @@ -58,11 +58,11 @@ def log_notice(notice)

private

sig { params(package_manager: T.nilable(PackageManagerBase)).returns(T.nilable(Dependabot::Notice)) }
sig { params(package_manager: T.nilable(Ecosystem::VersionManager)).returns(T.nilable(Dependabot::Notice)) }
def create_deprecation_notice(package_manager)
return unless package_manager

return unless package_manager.is_a?(PackageManagerBase)
return unless package_manager.is_a?(Ecosystem::VersionManager)

Notice.generate_pm_deprecation_notice(
package_manager
Expand Down
6 changes: 3 additions & 3 deletions updater/spec/dependabot/notices_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require "spec_helper"
require "dependabot/updater"
require "dependabot/package_manager"
require "dependabot/ecosystem"
require "dependabot/notices"
require "dependabot/notices_helpers"

Expand All @@ -23,7 +23,7 @@ def initialize
let(:dummy_instance) { dummy_class.new }

let(:package_manager) do
Class.new(Dependabot::PackageManagerBase) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def name
"bundler"
end
Expand Down Expand Up @@ -81,7 +81,7 @@ def supported_versions

context "when package manager is not deprecated" do
let(:package_manager) do
Class.new(Dependabot::PackageManagerBase) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def name
"bundler"
end
Expand Down
4 changes: 2 additions & 2 deletions updater/spec/dependabot/updater/pull_request_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require "spec_helper"
require "dependabot/updater"
require "dependabot/package_manager"
require "dependabot/ecosystem"
require "dependabot/notices"
require "dependabot/service"

Expand All @@ -26,7 +26,7 @@ def initialize(service = nil)
let(:service) { instance_double(Dependabot::Service) }

let(:package_manager) do
Class.new(Dependabot::PackageManagerBase) do
Class.new(Dependabot::Ecosystem::VersionManager) do
def name
"bundler"
end
Expand Down
6 changes: 3 additions & 3 deletions updater/spec/support/dummy_pkg_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# typed: false
# frozen_string_literal: true

require "dependabot/package_manager"
require "dependabot/ecosystem"
require "dependabot/dependency_file"

# This module provides some shortcuts for working with our two mock RubyGems packages:
Expand Down Expand Up @@ -63,8 +63,8 @@ def updated_bundler_files_hash(fixture: "bundler")
updated_bundler_files(fixture: fixture).map(&:to_h)
end

# Stub PackageManagerBase
class StubPackageManager < Dependabot::PackageManagerBase
# Stub Ecosystem::VersionManager
class StubPackageManager < Dependabot::Ecosystem::VersionManager
def initialize(name:, version:, deprecated_versions: [], unsupported_versions: [], supported_versions: [])
@name = name
@version = version
Expand Down

0 comments on commit a8bc22d

Please sign in to comment.