Skip to content

Commit

Permalink
Change default to Bundler v2 when unsupported feature flag is on and …
Browse files Browse the repository at this point in the history
…Gemfile.lock exists (#10617)

* change the default fallback (when Gemlock file exists but version is not defined) version to Bundler v2 when v1 unsupported feature flag is enabled.
  • Loading branch information
kbukum1 authored Sep 17, 2024
1 parent 989987b commit 95f169b
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions bundler/lib/dependabot/bundler/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
# typed: true
# typed: strong
# frozen_string_literal: true

module Dependabot
module Bundler
module Helpers
extend T::Sig
extend T::Helpers

V1 = "1"
V2 = "2"
# If we are updating a project with no Gemfile.lock, we default to the
# newest version we support
DEFAULT = V2
# If we are updating a project with a Gemfile.lock that does not specify
# the version it was bundled with, we failover to V1 on the assumption
# it was created with an old version that didn't add this information
FAILOVER = V1

BUNDLER_MAJOR_VERSION_REGEX = /BUNDLED WITH\s+(?<version>\d+)\./m

sig { params(lockfile: T.nilable(Dependabot::DependencyFile)).returns(String) }
def self.bundler_version(lockfile)
return DEFAULT unless lockfile

if (matches = lockfile.content.match(BUNDLER_MAJOR_VERSION_REGEX))
if (matches = lockfile.content&.match(BUNDLER_MAJOR_VERSION_REGEX))
matches[:version].to_i >= 2 ? V2 : V1
elsif Dependabot::Experiments.enabled?(:bundler_v1_unsupported_error)
DEFAULT
else
FAILOVER
failover_version
end
end

# If we are updating a project with a Gemfile.lock that does not specify
# the version it was bundled with, we failover to V1 on the assumption
# it was created with an old version that didn't add this information
sig { returns(String) }
def self.failover_version
return V2 if Dependabot::Experiments.enabled?(:bundler_v1_unsupported_error)

V1
end

sig { params(lockfile: T.nilable(Dependabot::DependencyFile)).returns(String) }
def self.detected_bundler_version(lockfile)
return "unknown" unless lockfile

if (matches = lockfile.content.match(BUNDLER_MAJOR_VERSION_REGEX))
if (matches = lockfile.content&.match(BUNDLER_MAJOR_VERSION_REGEX))
matches[:version].to_i.to_s
else
"unspecified"
Expand Down

0 comments on commit 95f169b

Please sign in to comment.