-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc2e621
commit 558d758
Showing
3 changed files
with
85 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
swift/lib/dependabot/swift/update_checker/requirements_updater.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/update_checkers/base" | ||
require "dependabot/swift/native_requirement" | ||
require "dependabot/swift/version" | ||
|
||
module Dependabot | ||
module Swift | ||
class UpdateChecker < Dependabot::UpdateCheckers::Base | ||
class RequirementsUpdater | ||
ALLOWED_UPDATE_STRATEGIES = | ||
%i(lockfile_only bump_versions bump_versions_if_necessary).freeze | ||
|
||
def initialize(requirements:, update_strategy:, target_version:) | ||
@requirements = requirements | ||
@update_strategy = update_strategy | ||
|
||
check_update_strategy | ||
|
||
return unless target_version && Version.correct?(target_version) | ||
|
||
@target_version = Version.new(target_version) | ||
end | ||
|
||
def updated_requirements | ||
return requirements if update_strategy == :lockfile_only | ||
|
||
NativeRequirement.map_requirements(requirements) do |requirement| | ||
if update_strategy == :bump_versions_if_necessary | ||
requirement.update_if_needed(target_version) | ||
else | ||
requirement.update(target_version) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :requirements, :update_strategy, :target_version | ||
|
||
def check_update_strategy | ||
return if ALLOWED_UPDATE_STRATEGIES.include?(update_strategy) | ||
|
||
raise "Unknown update strategy: #{update_strategy}" | ||
end | ||
end | ||
end | ||
end | ||
end |