Skip to content
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
9 changes: 2 additions & 7 deletions bin/dry-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
cache_steps: [],
write: false,
clone: false,
lockfile_only: false,
reject_external_code: false,
requirements_update_strategy: nil,
commit: nil,
Expand Down Expand Up @@ -186,15 +185,11 @@
$options[:write] = true
end

opts.on("--lockfile-only", "Only update the lockfile") do |_value|
$options[:lockfile_only] = true
end

opts.on("--reject-external-code", "Reject external code") do |_value|
$options[:reject_external_code] = true
end

opts_req_desc = "Options: auto, widen_ranges, bump_versions or " \
opts_req_desc = "Options: lockfile_only, auto, widen_ranges, bump_versions or " \
"bump_versions_if_necessary"
opts.on("--requirements-update-strategy STRATEGY", opts_req_desc) do |value|
value = nil if value == "auto"
Expand Down Expand Up @@ -695,7 +690,7 @@ def security_fix?(dependency)
puts " => latest allowed version is #{latest_allowed_version || dep.version}"

requirements_to_unlock =
if $options[:lockfile_only] || !checker.requirements_unlocked_or_can_be?
if !checker.requirements_unlocked_or_can_be?
if checker.can_update?(requirements_to_unlock: :none) then :none
else
:update_not_possible
Expand Down
10 changes: 8 additions & 2 deletions bundler/lib/dependabot/bundler/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def updated_requirements
end

def requirements_unlocked_or_can_be?
dependency.requirements.
select { |r| requirement_class.new(r[:requirement]).specific? }.
return true if requirements_unlocked?
return false if requirements_update_strategy == :lockfile_only

dependency.specific_requirements.
all? do |req|
file = dependency_files.find { |f| f.name == req.fetch(:file) }
updated = FileUpdater::RequirementReplacer.new(
Expand Down Expand Up @@ -109,6 +111,10 @@ def conflicting_dependencies

private

def requirements_unlocked?
dependency.specific_requirements.none?
end

def latest_version_resolvable_with_full_unlock?
return false unless latest_version

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RequirementsUpdater
class UnfixableRequirement < StandardError; end

ALLOWED_UPDATE_STRATEGIES =
%i(bump_versions bump_versions_if_necessary).freeze
%i(lockfile_only bump_versions bump_versions_if_necessary).freeze

def initialize(requirements:, update_strategy:, updated_source:,
latest_version:, latest_resolvable_version:)
Expand All @@ -27,6 +27,8 @@ def initialize(requirements:, update_strategy:, updated_source:,
end

def updated_requirements
return requirements if update_strategy == :lockfile_only

requirements.map do |req|
if req[:file].include?(".gemspec")
update_gemspec_requirement(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,5 +505,13 @@
end
end
end

context "when lockfile_only configured" do
let(:update_strategy) { :lockfile_only }

it "does not change any requirements" do
expect(updated_requirements).to eq(requirements)
end
end
end
end
16 changes: 15 additions & 1 deletion bundler/spec/dependabot/bundler/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
dependency_files: dependency_files,
credentials: credentials,
ignored_versions: ignored_versions,
security_advisories: security_advisories
security_advisories: security_advisories,
requirements_update_strategy: requirements_update_strategy
)
end
let(:credentials) do
Expand All @@ -33,6 +34,7 @@
let(:directory) { "/" }
let(:ignored_versions) { [] }
let(:security_advisories) { [] }
let(:requirements_update_strategy) { nil }

let(:dependency) do
Dependabot::Dependency.new(
Expand Down Expand Up @@ -1795,6 +1797,12 @@
end

it { is_expected.to eq(true) }

context "and with the lockfile-only requirements update strategy set" do
let(:requirements_update_strategy) { :lockfile_only }

it { is_expected.to eq(true) }
end
end

context "with a sub-dependency" do
Expand All @@ -1821,6 +1829,12 @@

it { is_expected.to eq(true) }
end

context "but with the lockfile-only requirements update strategy set" do
let(:requirements_update_strategy) { :lockfile_only }

it { is_expected.to eq(false) }
end
end

# For now we always let git dependencies through
Expand Down
8 changes: 8 additions & 0 deletions cargo/lib/dependabot/cargo/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ def updated_requirements
).updated_requirements
end

def requirements_unlocked_or_can_be?
requirements_update_strategy != :lockfile_only
end

def requirements_update_strategy
# If passed in as an option (in the base class) honour that option
return @requirements_update_strategy.to_sym if @requirements_update_strategy

# Otherwise, widen ranges for libraries and bump versions for apps
library? ? :bump_versions_if_necessary : :bump_versions
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UnfixableRequirement < StandardError; end

VERSION_REGEX = /[0-9]+(?:\.[A-Za-z0-9\-*]+)*/
ALLOWED_UPDATE_STRATEGIES =
%i(bump_versions bump_versions_if_necessary).freeze
%i(lockfile_only bump_versions bump_versions_if_necessary).freeze

def initialize(requirements:, updated_source:, update_strategy:,
target_version:)
Expand All @@ -34,6 +34,8 @@ def initialize(requirements:, updated_source:, update_strategy:,
end

def updated_requirements
return requirements if update_strategy == :lockfile_only

# NOTE: Order is important here. The FileUpdater needs the updated
# requirement at index `i` to correspond to the previous requirement
# at the same index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,13 @@
end
end
end

context "for a lockfile_only strategy" do
let(:update_strategy) { :lockfile_only }

it "does not change any requirements" do
expect(updater.updated_requirements).to eq(requirements)
end
end
end
end
16 changes: 15 additions & 1 deletion cargo/spec/dependabot/cargo/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
credentials: credentials,
ignored_versions: ignored_versions,
raise_on_ignored: raise_on_ignored,
security_advisories: security_advisories
security_advisories: security_advisories,
requirements_update_strategy: requirements_update_strategy
)
end

let(:ignored_versions) { [] }
let(:raise_on_ignored) { false }
let(:security_advisories) { [] }
let(:requirements_update_strategy) { nil }
let(:credentials) do
[{
"type" => "git_source",
Expand Down Expand Up @@ -483,4 +485,16 @@
end
end
end

context "#requirements_unlocked_or_can_be?" do
subject { checker.requirements_unlocked_or_can_be? }

it { is_expected.to eq(true) }

context "with the lockfile-only requirements update strategy set" do
let(:requirements_update_strategy) { :lockfile_only }

it { is_expected.to eq(false) }
end
end
end
4 changes: 4 additions & 0 deletions common/lib/dependabot/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ def eql?(other)
self == other
end

def specific_requirements
requirements.select { |r| requirement_class.new(r[:requirement]).specific? }
end

def requirement_class
Utils.requirement_class_for_package_manager(package_manager)
end
Expand Down
4 changes: 4 additions & 0 deletions composer/lib/dependabot/composer/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def updated_requirements
).updated_requirements
end

def requirements_unlocked_or_can_be?
requirements_update_strategy != :lockfile_only
end

def requirements_update_strategy
# If passed in as an option (in the base class) honour that option
return @requirements_update_strategy.to_sym if @requirements_update_strategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RequirementsUpdater
OR_SEPARATOR = /(?<=[a-zA-Z0-9*])[\s,]*\|\|?\s*/
SEPARATOR = /(?:#{AND_SEPARATOR})|(?:#{OR_SEPARATOR})/
ALLOWED_UPDATE_STRATEGIES =
%i(widen_ranges bump_versions bump_versions_if_necessary).freeze
%i(lockfile_only widen_ranges bump_versions bump_versions_if_necessary).freeze

def initialize(requirements:, update_strategy:,
latest_resolvable_version:)
Expand All @@ -35,6 +35,7 @@ def initialize(requirements:, update_strategy:,
end

def updated_requirements
return requirements if update_strategy == :lockfile_only
return requirements unless latest_resolvable_version

requirements.map { |req| updated_requirement(req) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,5 +705,13 @@
end
end
end

context "with lockfile_only as the update strategy" do
let(:update_strategy) { :lockfile_only }

it "does not update any requirements" do
expect(updater.updated_requirements).to eq(requirements)
end
end
end
end
16 changes: 15 additions & 1 deletion composer/spec/dependabot/composer/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
credentials: credentials,
ignored_versions: ignored_versions,
raise_on_ignored: raise_on_ignored,
security_advisories: security_advisories
security_advisories: security_advisories,
requirements_update_strategy: requirements_update_strategy
)
end

Expand All @@ -31,6 +32,7 @@
let(:ignored_versions) { [] }
let(:raise_on_ignored) { false }
let(:security_advisories) { [] }
let(:requirements_update_strategy) { nil }
let(:dependency_name) { "monolog/monolog" }
let(:dependency_version) { "1.0.1" }
let(:requirements) do
Expand Down Expand Up @@ -871,4 +873,16 @@
end
end
end

context "#requirements_unlocked_or_can_be?" do
subject { checker.requirements_unlocked_or_can_be? }

it { is_expected.to eq(true) }

context "with the lockfile-only requirements update strategy set" do
let(:requirements_update_strategy) { :lockfile_only }

it { is_expected.to eq(false) }
end
end
end
4 changes: 4 additions & 0 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def updated_requirements
).updated_requirements
end

def requirements_unlocked_or_can_be?
requirements_update_strategy != :lockfile_only
end

def requirements_update_strategy
# If passed in as an option (in the base class) honour that option
return @requirements_update_strategy.to_sym if @requirements_update_strategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UpdateChecker
class RequirementsUpdater
VERSION_REGEX = /[0-9]+(?:\.[A-Za-z0-9\-_]+)*/
SEPARATOR = /(?<=[a-zA-Z0-9*])[\s|]+(?![\s|-])/
ALLOWED_UPDATE_STRATEGIES = %i(widen_ranges bump_versions bump_versions_if_necessary).freeze
ALLOWED_UPDATE_STRATEGIES = %i(lockfile_only widen_ranges bump_versions bump_versions_if_necessary).freeze

def initialize(requirements:, updated_source:, update_strategy:,
latest_resolvable_version:)
Expand All @@ -32,6 +32,8 @@ def initialize(requirements:, updated_source:, update_strategy:,
end

def updated_requirements
return requirements if update_strategy == :lockfile_only

requirements.map do |req|
req = req.merge(source: updated_source)
next req unless latest_resolvable_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,5 +606,13 @@
end
end
end

context "for a requirement being left alone" do
let(:update_strategy) { :lockfile_only }

it "does not update any requirements" do
expect(updater.updated_requirements).to eq(requirements)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
credentials: credentials,
ignored_versions: ignored_versions,
security_advisories: security_advisories,
requirements_update_strategy: requirements_update_strategy,
options: options
)
end
let(:ignored_versions) { [] }
let(:security_advisories) { [] }
let(:requirements_update_strategy) { nil }
let(:dependency_files) { project_dependency_files("npm6/no_lockfile") }
let(:options) { {} }

Expand Down Expand Up @@ -1214,6 +1216,18 @@
end
end

context "#requirements_unlocked_or_can_be?" do
subject { checker.requirements_unlocked_or_can_be? }

it { is_expected.to eq(true) }

context "with the lockfile-only requirements update strategy set" do
let(:requirements_update_strategy) { :lockfile_only }

it { is_expected.to eq(false) }
end
end

context "#updated_dependencies_after_full_unlock" do
let(:dependency_files) { project_dependency_files("npm6/no_lockfile") }
let(:dependency) do
Expand Down
4 changes: 4 additions & 0 deletions python/lib/dependabot/python/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def updated_requirements
).updated_requirements
end

def requirements_unlocked_or_can_be?
requirements_update_strategy != :lockfile_only
end

def requirements_update_strategy
# If passed in as an option (in the base class) honour that option
return @requirements_update_strategy.to_sym if @requirements_update_strategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def initialize(requirements:, update_strategy:, has_lockfile:,
end

def updated_requirements
return requirements if update_strategy == :lockfile_only

requirements.map do |req|
case req[:file]
when /setup\.(?:py|cfg)$/ then updated_setup_requirement(req)
Expand Down
Loading