From 869bacb4fb0772711cf98bdc9638f95206f1d623 Mon Sep 17 00:00:00 2001 From: Alfred Mazimbe Date: Wed, 4 Dec 2024 14:54:21 +0000 Subject: [PATCH] Add support for git-submodules ecosystem metrics collection --- .../dependabot/git_submodules/file_parser.rb | 30 ++++++++++++++ .../git_submodules/package_manager.rb | 41 +++++++++++++++++++ .../git_submodules/file_parser_spec.rb | 18 ++++++++ .../git_submodules/package_manager_spec.rb | 36 ++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 git_submodules/lib/dependabot/git_submodules/package_manager.rb create mode 100644 git_submodules/spec/dependabot/git_submodules/package_manager_spec.rb diff --git a/git_submodules/lib/dependabot/git_submodules/file_parser.rb b/git_submodules/lib/dependabot/git_submodules/file_parser.rb index e55bad0256..d94050d3c6 100644 --- a/git_submodules/lib/dependabot/git_submodules/file_parser.rb +++ b/git_submodules/lib/dependabot/git_submodules/file_parser.rb @@ -8,6 +8,7 @@ require "dependabot/file_parsers" require "dependabot/file_parsers/base" require "dependabot/shared_helpers" +require "dependabot/git_submodules/package_manager" module Dependabot module GitSubmodules @@ -42,6 +43,16 @@ def parse end end + sig { returns(Ecosystem) } + def ecosystem + @ecosystem ||= T.let(begin + Ecosystem.new( + name: ECOSYSTEM, + package_manager: package_manager + ) + end, T.nilable(Dependabot::Ecosystem)) + end + private sig { params(url: String).returns(String) } @@ -77,6 +88,25 @@ def check_required_files raise "No #{filename}!" unless get_original_file(filename) end end + + sig { returns(Ecosystem::VersionManager) } + def package_manager + @package_manager ||= T.let( + PackageManager.new(T.must(git_version)), + T.nilable(Dependabot::GitSubmodules::PackageManager) + ) + end + + sig { returns(T.nilable(String)) } + def git_version + @git_version ||= T.let( + begin + version = SharedHelpers.run_shell_command("git --version") + version.match(Dependabot::Ecosystem::VersionManager::DEFAULT_VERSION_PATTERN)&.captures&.first + end, + T.nilable(String) + ) + end end end end diff --git a/git_submodules/lib/dependabot/git_submodules/package_manager.rb b/git_submodules/lib/dependabot/git_submodules/package_manager.rb new file mode 100644 index 0000000000..7eb2a167cd --- /dev/null +++ b/git_submodules/lib/dependabot/git_submodules/package_manager.rb @@ -0,0 +1,41 @@ +# typed: strong +# frozen_string_literal: true + +require "sorbet-runtime" +require "dependabot/ecosystem" +require "dependabot/git_submodules/version" + +module Dependabot + module GitSubmodules + ECOSYSTEM = "git_submodules" + PACKAGE_MANAGER = "git_submodules" + SUPPORTED_GIT_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) + + # When a version is going to be unsupported, it will be added here + DEPRECATED_GIT_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) + + class PackageManager < Dependabot::Ecosystem::VersionManager + extend T::Sig + + sig { params(raw_version: String).void } + def initialize(raw_version) + super( + PACKAGE_MANAGER, + Version.new(raw_version), + DEPRECATED_GIT_VERSIONS, + SUPPORTED_GIT_VERSIONS + ) + end + + sig { returns(T::Boolean) } + def deprecated? + false + end + + sig { returns(T::Boolean) } + def unsupported? + false + end + end + end +end diff --git a/git_submodules/spec/dependabot/git_submodules/file_parser_spec.rb b/git_submodules/spec/dependabot/git_submodules/file_parser_spec.rb index 26b2f387de..993107f289 100644 --- a/git_submodules/spec/dependabot/git_submodules/file_parser_spec.rb +++ b/git_submodules/spec/dependabot/git_submodules/file_parser_spec.rb @@ -121,5 +121,23 @@ end end end + + describe "#ecosystem" do + subject(:ecosystem) { parser.ecosystem } + + it "has the correct name" do + expect(ecosystem.name).to eq "git_submodules" + end + + describe "#package_manager" do + subject(:package_manager) { ecosystem.package_manager } + + it "returns the correct package manager" do + expect(package_manager.name).to eq "git_submodules" + expect(package_manager.requirement).to be_nil + expect(package_manager.version.to_s).to eq "2.34.1" + end + end + end end end diff --git a/git_submodules/spec/dependabot/git_submodules/package_manager_spec.rb b/git_submodules/spec/dependabot/git_submodules/package_manager_spec.rb new file mode 100644 index 0000000000..5e4b3ebec0 --- /dev/null +++ b/git_submodules/spec/dependabot/git_submodules/package_manager_spec.rb @@ -0,0 +1,36 @@ +# typed: false +# frozen_string_literal: true + +require "dependabot/git_submodules/package_manager" +require "dependabot/ecosystem" +require "spec_helper" + +RSpec.describe Dependabot::GitSubmodules::PackageManager do + subject(:package_manager) { described_class.new(version) } + + let(:version) { "2.1.1" } + + describe "#version" do + it "returns the version" do + expect(package_manager.version.to_s).to eq version + end + end + + describe "#name" do + it "returns the name" do + expect(package_manager.name).to eq(Dependabot::GitSubmodules::PACKAGE_MANAGER) + end + end + + describe "#deprecated_versions" do + it "returns deprecated versions" do + expect(package_manager.deprecated_versions).to eq(Dependabot::GitSubmodules::DEPRECATED_GIT_VERSIONS) + end + end + + describe "#supported_versions" do + it "returns supported versions" do + expect(package_manager.supported_versions).to eq(Dependabot::GitSubmodules::SUPPORTED_GIT_VERSIONS) + end + end +end