diff --git a/docker/lib/dependabot/docker/file_parser.rb b/docker/lib/dependabot/docker/file_parser.rb index f88abcdb24..671ee0cb8d 100644 --- a/docker/lib/dependabot/docker/file_parser.rb +++ b/docker/lib/dependabot/docker/file_parser.rb @@ -8,6 +8,7 @@ require "dependabot/file_parsers/base" require "dependabot/errors" require "sorbet-runtime" +require "dependabot/docker/package_manager" module Dependabot module Docker @@ -42,6 +43,17 @@ class FileParser < Dependabot::FileParsers::Base IMAGE_SPEC = %r{^(#{REGISTRY}/)?#{IMAGE}#{TAG}?(?:@sha256:#{DIGEST})?#{NAME}?}x + sig { returns(Ecosystem) } + def ecosystem + @ecosystem ||= T.let( + Ecosystem.new( + name: ECOSYSTEM, + package_manager: DockerPackageManager.new + ), + T.nilable(Ecosystem) + ) + end + # rubocop:disable Metrics/AbcSize sig { override.returns(T::Array[Dependabot::Dependency]) } def parse diff --git a/docker/lib/dependabot/docker/package_manager.rb b/docker/lib/dependabot/docker/package_manager.rb new file mode 100644 index 0000000000..11d13845dc --- /dev/null +++ b/docker/lib/dependabot/docker/package_manager.rb @@ -0,0 +1,53 @@ +# typed: strong +# frozen_string_literal: true + +require "sorbet-runtime" +require "dependabot/docker/version" +require "dependabot/ecosystem" +require "dependabot/docker/requirement" + +module Dependabot + module Docker + ECOSYSTEM = "docker" + + SUPPORTED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) + + DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) + + class DockerPackageManager < Dependabot::Ecosystem::VersionManager + extend T::Sig + + NAME = "docker" + + # As dockerfile updater is a inhouse custom utility, We use a placeholder + # version number for dockerfile updater + VERSION = "1.0.0" + + SUPPORTED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) + + DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version]) + + sig do + void + end + def initialize + super( + name: NAME, + version: Version.new(VERSION), + deprecated_versions: DEPRECATED_VERSIONS, + supported_versions: SUPPORTED_VERSIONS + ) + end + + sig { override.returns(T::Boolean) } + def deprecated? + false + end + + sig { override.returns(T::Boolean) } + def unsupported? + false + end + end + end +end diff --git a/docker/spec/dependabot/docker/docker_package_manager_spec.rb b/docker/spec/dependabot/docker/docker_package_manager_spec.rb new file mode 100644 index 0000000000..2b8aaf24c0 --- /dev/null +++ b/docker/spec/dependabot/docker/docker_package_manager_spec.rb @@ -0,0 +1,33 @@ +# typed: false +# frozen_string_literal: true + +require "dependabot/docker/package_manager" +require "dependabot/ecosystem" +require "spec_helper" + +RSpec.describe Dependabot::Docker::DockerPackageManager do + let(:package_manager) do + described_class.new + end + + describe "#initialize" do + context "when docker package manager is initialised" do + it "sets the name and version correctly" do + expect(package_manager.name).to eq(Dependabot::Docker::DockerPackageManager::NAME) + expect(package_manager.version.to_s).to eq("1.0.0") + end + end + + describe "#deprecated?" do + it "returns always false" do + expect(package_manager.deprecated?).to be false + end + end + + describe "#unsupported?" do + it "returns always false" do + expect(package_manager.unsupported?).to be false + end + end + end +end diff --git a/docker/spec/dependabot/docker/file_parser_spec.rb b/docker/spec/dependabot/docker/file_parser_spec.rb index f0ce0e95dc..c1adb7e8cd 100644 --- a/docker/spec/dependabot/docker/file_parser_spec.rb +++ b/docker/spec/dependabot/docker/file_parser_spec.rb @@ -677,6 +677,14 @@ expect(dependency.name).to eq("ubuntu") expect(dependency.version).to eq("artful") expect(dependency.requirements).to eq(expected_requirements) + + ecosystem = parser.ecosystem + + expect(ecosystem.name).to eq("docker") + expect(ecosystem.package_manager.name).to eq("docker") + + expect(ecosystem.package_manager.deprecated?).to be false + expect(ecosystem.package_manager.unsupported?).to be false end end end