From a8bc22d3e4af7e5149219f30a2b7728d1cc1df98 Mon Sep 17 00:00:00 2001 From: Kamil Bukum Date: Tue, 22 Oct 2024 19:02:36 -0700 Subject: [PATCH] update package manager to use version manager in ecosystem --- bundler/lib/dependabot/bundler/file_parser.rb | 2 +- common/lib/dependabot/ecosystem.rb | 34 +++++++++---------- common/lib/dependabot/file_parsers/base.rb | 4 +-- common/lib/dependabot/notices.rb | 6 ++-- .../spec/dependabot/file_parsers/base_spec.rb | 6 ++-- common/spec/dependabot/notices_spec.rb | 4 +-- .../spec/dependabot/package_manager_spec.rb | 8 ++--- .../lib/dependabot/composer/file_parser.rb | 2 +- silent/lib/dependabot/silent/file_parser.rb | 4 +-- .../lib/dependabot/silent/package_manager.rb | 4 +-- updater/lib/dependabot/dependency_snapshot.rb | 4 +-- updater/lib/dependabot/notices_helpers.rb | 8 ++--- .../spec/dependabot/notices_helpers_spec.rb | 6 ++-- .../updater/pull_request_helpers_spec.rb | 4 +-- updater/spec/support/dummy_pkg_helpers.rb | 6 ++-- 15 files changed, 51 insertions(+), 51 deletions(-) diff --git a/bundler/lib/dependabot/bundler/file_parser.rb b/bundler/lib/dependabot/bundler/file_parser.rb index 88b2a96d7fe..a7de99323db 100644 --- a/bundler/lib/dependabot/bundler/file_parser.rb +++ b/bundler/lib/dependabot/bundler/file_parser.rb @@ -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 diff --git a/common/lib/dependabot/ecosystem.rb b/common/lib/dependabot/ecosystem.rb index 192a763b79a..0fd6f3baddc 100644 --- a/common/lib/dependabot/ecosystem.rb +++ b/common/lib/dependabot/ecosystem.rb @@ -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] an array of deprecated versions. # @param supported_versions [Array] an array of supported versions. # @param requirement [T.nilable(Requirement)] the version requirements, optional. @@ -24,8 +24,8 @@ 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) @@ -33,15 +33,15 @@ class VersionManager 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]) @@ -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 @@ -91,7 +91,7 @@ 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. @@ -99,7 +99,7 @@ def deprecated? # 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. @@ -113,7 +113,7 @@ def raise_if_unsupported! raise ToolVersionNotSupported.new( name, - current_version.to_s, + version.to_s, supported_versions_message ) end @@ -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, diff --git a/common/lib/dependabot/file_parsers/base.rb b/common/lib/dependabot/file_parsers/base.rb index 450e82bf06c..b5e203279aa 100644 --- a/common/lib/dependabot/file_parsers/base.rb +++ b/common/lib/dependabot/file_parsers/base.rb @@ -3,7 +3,7 @@ require "sorbet-runtime" require "dependabot/credential" -require "dependabot/package_manager" +require "dependabot/ecosystem" module Dependabot module FileParsers @@ -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 diff --git a/common/lib/dependabot/notices.rb b/common/lib/dependabot/notices.rb index face593224b..89447a5a254 100644 --- a/common/lib/dependabot/notices.rb +++ b/common/lib/dependabot/notices.rb @@ -2,7 +2,7 @@ # frozen_string_literal: true require "sorbet-runtime" -require "dependabot/package_manager" +require "dependabot/ecosystem" module Dependabot class Notice @@ -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) diff --git a/common/spec/dependabot/file_parsers/base_spec.rb b/common/spec/dependabot/file_parsers/base_spec.rb index dc6e99be775..19092b9e09d 100644 --- a/common/spec/dependabot/file_parsers/base_spec.rb +++ b/common/spec/dependabot/file_parsers/base_spec.rb @@ -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 @@ -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 diff --git a/common/spec/dependabot/notices_spec.rb b/common/spec/dependabot/notices_spec.rb index cde5924755d..f8ad4c35f58 100644 --- a/common/spec/dependabot/notices_spec.rb +++ b/common/spec/dependabot/notices_spec.rb @@ -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 diff --git a/common/spec/dependabot/package_manager_spec.rb b/common/spec/dependabot/package_manager_spec.rb index 8e265514320..d246dc58047 100644 --- a/common/spec/dependabot/package_manager_spec.rb +++ b/common/spec/dependabot/package_manager_spec.rb @@ -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 @@ -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 diff --git a/composer/lib/dependabot/composer/file_parser.rb b/composer/lib/dependabot/composer/file_parser.rb index d2f888ba75d..1feaa1b4ceb 100644 --- a/composer/lib/dependabot/composer/file_parser.rb +++ b/composer/lib/dependabot/composer/file_parser.rb @@ -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 diff --git a/silent/lib/dependabot/silent/file_parser.rb b/silent/lib/dependabot/silent/file_parser.rb index a7c4f7203dc..917d381acaf 100644 --- a/silent/lib/dependabot/silent/file_parser.rb +++ b/silent/lib/dependabot/silent/file_parser.rb @@ -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" @@ -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? diff --git a/silent/lib/dependabot/silent/package_manager.rb b/silent/lib/dependabot/silent/package_manager.rb index 7f8d54f10f3..3980d15c210 100644 --- a/silent/lib/dependabot/silent/package_manager.rb +++ b/silent/lib/dependabot/silent/package_manager.rb @@ -3,7 +3,7 @@ require "sorbet-runtime" require "dependabot/silent/version" -require "dependabot/package_manager" +require "dependabot/ecosystem" module Dependabot module Silent @@ -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 } diff --git a/updater/lib/dependabot/dependency_snapshot.rb b/updater/lib/dependabot/dependency_snapshot.rb index 02b03c4ef46..5f58552bbd5 100644 --- a/updater/lib/dependabot/dependency_snapshot.rb +++ b/updater/lib/dependabot/dependency_snapshot.rb @@ -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 @@ -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| diff --git a/updater/lib/dependabot/notices_helpers.rb b/updater/lib/dependabot/notices_helpers.rb index c8f52474df8..8c89d0daa75 100644 --- a/updater/lib/dependabot/notices_helpers.rb +++ b/updater/lib/dependabot/notices_helpers.rb @@ -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. @@ -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 @@ -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 diff --git a/updater/spec/dependabot/notices_helpers_spec.rb b/updater/spec/dependabot/notices_helpers_spec.rb index 45ac2b598b3..ee9d3f1bdde 100644 --- a/updater/spec/dependabot/notices_helpers_spec.rb +++ b/updater/spec/dependabot/notices_helpers_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" require "dependabot/updater" -require "dependabot/package_manager" +require "dependabot/ecosystem" require "dependabot/notices" require "dependabot/notices_helpers" @@ -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 @@ -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 diff --git a/updater/spec/dependabot/updater/pull_request_helpers_spec.rb b/updater/spec/dependabot/updater/pull_request_helpers_spec.rb index f48f5cbf85c..ffd4521a912 100644 --- a/updater/spec/dependabot/updater/pull_request_helpers_spec.rb +++ b/updater/spec/dependabot/updater/pull_request_helpers_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" require "dependabot/updater" -require "dependabot/package_manager" +require "dependabot/ecosystem" require "dependabot/notices" require "dependabot/service" @@ -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 diff --git a/updater/spec/support/dummy_pkg_helpers.rb b/updater/spec/support/dummy_pkg_helpers.rb index 2750b821bdf..f1dc942adc3 100644 --- a/updater/spec/support/dummy_pkg_helpers.rb +++ b/updater/spec/support/dummy_pkg_helpers.rb @@ -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: @@ -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