Skip to content

Commit

Permalink
Add support for git-submodules ecosystem metrics collection (#11053)
Browse files Browse the repository at this point in the history
  • Loading branch information
amazimbe authored Dec 4, 2024
1 parent fc28e3c commit a7e5899
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
30 changes: 30 additions & 0 deletions git_submodules/lib/dependabot/git_submodules/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions git_submodules/lib/dependabot/git_submodules/package_manager.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions git_submodules/spec/dependabot/git_submodules/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a7e5899

Please sign in to comment.