Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bundler v1 Deprecation Warning #10421

Merged
merged 7 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bundler/lib/dependabot/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require "dependabot/bundler/metadata_finder"
require "dependabot/bundler/requirement"
require "dependabot/bundler/version"
require "dependabot/bundler/package_manager"

require "dependabot/pull_request_creator/labeler"
Dependabot::PullRequestCreator::Labeler
Expand Down
7 changes: 7 additions & 0 deletions bundler/lib/dependabot/bundler/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
module Dependabot
module Bundler
class FileParser < Dependabot::FileParsers::Base
extend T::Sig
require "dependabot/file_parsers/base/dependency_set"
require "dependabot/bundler/file_parser/file_preparer"
require "dependabot/bundler/file_parser/gemfile_declaration_finder"
require "dependabot/bundler/file_parser/gemspec_declaration_finder"

sig { override.returns(T::Array[Dependabot::Dependency]) }
def parse
dependency_set = DependencySet.new
dependency_set += gemfile_dependencies
Expand All @@ -30,6 +32,11 @@ def parse
dependency_set.dependencies
end

sig { returns(PackageManagerBase) }
def package_manager
PackageManager.new(bundler_version)
end

private

def check_external_code(dependencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "dependabot/dependency_file"
require "dependabot/file_parsers/base"
require "dependabot/bundler/file_updater/gemspec_sanitizer"
require "dependabot/bundler/package_manager"

module Dependabot
module Bundler
Expand Down
53 changes: 53 additions & 0 deletions bundler/lib/dependabot/bundler/package_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"
require "dependabot/bundler/version"
require "dependabot/package_manager"

module Dependabot
module Bundler
PACKAGE_MANAGER = "bundler"

SUPPORTED_BUNDLER_VERSIONS = T.let([
Version.new("2")
].freeze, T::Array[Dependabot::Version])

DEPRECATED_BUNDLER_VERSIONS = T.let([
Version.new("1")
].freeze, T::Array[Dependabot::Version])

class PackageManager < PackageManagerBase
extend T::Sig

sig { params(version: T.any(String, Dependabot::Version)).void }
def initialize(version)
@version = T.let(Version.new(version), Dependabot::Version)
@name = T.let(PACKAGE_MANAGER, String)
@deprecated_versions = T.let(DEPRECATED_BUNDLER_VERSIONS, T::Array[Dependabot::Version])
@supported_versions = T.let(SUPPORTED_BUNDLER_VERSIONS, T::Array[Dependabot::Version])
end

sig { override.returns(String) }
attr_reader :name

sig { override.returns(Dependabot::Version) }
attr_reader :version

sig { override.returns(T::Array[Dependabot::Version]) }
attr_reader :deprecated_versions

sig { override.returns(T::Array[Dependabot::Version]) }
attr_reader :supported_versions

sig { override.returns(T::Boolean) }
def deprecated?
deprecated_versions.include?(version)
end
sig { override.returns(T::Boolean) }
def unsupported?
!deprecated? && version < supported_versions.first
end
end
end
end
6 changes: 6 additions & 0 deletions bundler/spec/dependabot/bundler/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -849,4 +849,10 @@
end
end
end

describe "#package_manager" do
it "returns the correct package manager" do
expect(parser.package_manager).to be_a(Dependabot::Bundler::PackageManager)
end
end
end
116 changes: 116 additions & 0 deletions bundler/spec/dependabot/bundler/package_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# typed: false
# frozen_string_literal: true

require "dependabot/bundler/package_manager"
require "dependabot/package_manager"
require "spec_helper"

RSpec.describe Dependabot::Bundler::PackageManager do
let(:package_manager) { described_class.new(version) }

describe "#initialize" do
context "when version is a String" do
let(:version) { "2" }

it "sets the version correctly" do
expect(package_manager.version).to eq(Dependabot::Bundler::Version.new(version))
end

it "sets the name correctly" do
expect(package_manager.name).to eq(Dependabot::Bundler::PACKAGE_MANAGER)
end

it "sets the deprecated_versions correctly" do
expect(package_manager.deprecated_versions).to eq(Dependabot::Bundler::DEPRECATED_BUNDLER_VERSIONS)
end

it "sets the supported_versions correctly" do
expect(package_manager.supported_versions).to eq(Dependabot::Bundler::SUPPORTED_BUNDLER_VERSIONS)
end
end

context "when version is a Dependabot::Bundler::Version" do
let(:version) { Dependabot::Bundler::Version.new("2") }

it "sets the version correctly" do
expect(package_manager.version).to eq(version)
end

it "sets the name correctly" do
expect(package_manager.name).to eq(Dependabot::Bundler::PACKAGE_MANAGER)
end

it "sets the deprecated_versions correctly" do
expect(package_manager.deprecated_versions).to eq(Dependabot::Bundler::DEPRECATED_BUNDLER_VERSIONS)
end

it "sets the supported_versions correctly" do
expect(package_manager.supported_versions).to eq(Dependabot::Bundler::SUPPORTED_BUNDLER_VERSIONS)
end
end
end

describe "#deprecated?" do
context "when version is deprecated?" do
let(:version) { "1" }

it "returns true" do
expect(package_manager.deprecated?).to be true
end
end

context "when version is not deprecated" do
let(:version) { "2" }

it "returns false" do
expect(package_manager.deprecated?).to be false
end
end
end

describe "#unsupported" do
context "when version is deprecated?" do
let(:version) { "1" }

it "returns false" do
expect(package_manager.unsupported?).to be false
end
end

context "when version is supported" do
let(:version) { "2" }

it "returns false" do
expect(package_manager.unsupported?).to be false
end
end

context "when version is unsupported?" do
let(:version) { "0.9" }

it "returns true" do
expect(package_manager.unsupported?).to be true
end
end
end

describe "#supported_versions" do
context "when there are supported versions" do
let(:version) { "2" }

it "returns the correct supported versions" do
expect(package_manager.supported_versions).to eq([Dependabot::Bundler::Version.new("2")])
end
end
end

describe "#deprecated_versions" do
context "when there are deprecated versions" do
let(:version) { "2" }

it "returns the correct deprecated versions" do
expect(package_manager.deprecated_versions).to eq([Dependabot::Bundler::Version.new("1")])
end
end
end
end
6 changes: 6 additions & 0 deletions common/lib/dependabot/file_parsers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

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

sig { returns(T.nilable(PackageManagerBase)) }
def package_manager
nil
end

private

sig { abstract.void }
Expand Down
Loading
Loading