-
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
ddc75d8
commit 6c5494d
Showing
10 changed files
with
395 additions
and
3 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
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
# 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 | ||
def initialize(requirements:, target_version:) | ||
@requirements = requirements | ||
|
||
return unless target_version && Version.correct?(target_version) | ||
|
||
@target_version = Version.new(target_version) | ||
end | ||
|
||
def updated_requirements | ||
NativeRequirement.map_requirements(requirements) do |requirement| | ||
requirement.update_if_needed(target_version) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :requirements, :target_version | ||
end | ||
end | ||
end | ||
end |
54 changes: 54 additions & 0 deletions
54
swift/lib/dependabot/swift/update_checker/version_resolver.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,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/update_checkers/base" | ||
require "dependabot/swift/file_parser/dependency_parser" | ||
require "dependabot/swift/file_updater/lockfile_updater" | ||
|
||
module Dependabot | ||
module Swift | ||
class UpdateChecker < Dependabot::UpdateCheckers::Base | ||
class VersionResolver | ||
def initialize(dependency:, manifest:, repo_contents_path:, credentials:) | ||
@dependency = dependency | ||
@manifest = manifest | ||
@credentials = credentials | ||
@repo_contents_path = repo_contents_path | ||
end | ||
|
||
def latest_resolvable_version | ||
@latest_resolvable_version ||= fetch_latest_resolvable_version | ||
end | ||
|
||
private | ||
|
||
def fetch_latest_resolvable_version | ||
updated_lockfile_content = FileUpdater::LockfileUpdater.new( | ||
dependencies: [dependency], | ||
manifest: manifest, | ||
repo_contents_path: repo_contents_path, | ||
credentials: credentials | ||
).updated_lockfile_content | ||
|
||
lockfile = DependencyFile.new( | ||
name: "Package.resolved", | ||
content: updated_lockfile_content | ||
) | ||
|
||
dependency_parser(manifest, lockfile).parse.find do |parsed_dep| | ||
parsed_dep.name == dependency.name | ||
end&.version | ||
end | ||
|
||
def dependency_parser(manifest, lockfile) | ||
FileParser::DependencyParser.new( | ||
dependency_files: [manifest, lockfile], | ||
repo_contents_path: repo_contents_path, | ||
credentials: credentials | ||
) | ||
end | ||
|
||
attr_reader :dependency, :manifest, :repo_contents_path, :credentials | ||
end | ||
end | ||
end | ||
end |
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,132 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "dependabot/dependency" | ||
require "dependabot/swift/file_parser" | ||
require "dependabot/swift/update_checker" | ||
require_common_spec "update_checkers/shared_examples_for_update_checkers" | ||
|
||
RSpec.describe Dependabot::Swift::UpdateChecker do | ||
it_behaves_like "an update checker" | ||
|
||
let(:checker) do | ||
described_class.new( | ||
dependency: dependency, | ||
dependency_files: dependency_files, | ||
repo_contents_path: repo_contents_path, | ||
credentials: github_credentials, | ||
security_advisories: security_advisories, | ||
ignored_versions: ignored_versions, | ||
raise_on_ignored: raise_on_ignored | ||
) | ||
end | ||
let(:project_name) { "ReactiveCocoa" } | ||
let(:repo_contents_path) { build_tmp_repo(project_name, path: "projects") } | ||
let(:dependency_files) { project_dependency_files(project_name) } | ||
let(:security_advisories) { [] } | ||
let(:ignored_versions) { [] } | ||
let(:raise_on_ignored) { false } | ||
|
||
let(:dependencies) do | ||
file_parser.parse | ||
end | ||
|
||
let(:file_parser) do | ||
Dependabot::Swift::FileParser.new( | ||
dependency_files: dependency_files, | ||
repo_contents_path: repo_contents_path, | ||
source: nil | ||
) | ||
end | ||
|
||
let(:dependency) { dependencies.find { |dep| dep.name == name } } | ||
|
||
let(:stub_upload_pack) do | ||
stub_request(:get, "#{url}.git/info/refs?service=git-upload-pack"). | ||
to_return( | ||
status: 200, | ||
body: fixture("git", "upload_packs", upload_pack_fixture), | ||
headers: { | ||
"content-type" => "application/x-git-upload-pack-advertisement" | ||
} | ||
) | ||
end | ||
|
||
context "with an up to date dependency" do | ||
let(:name) { "reactiveswift" } | ||
let(:url) { "https://github.com/ReactiveCocoa/ReactiveSwift" } | ||
let(:upload_pack_fixture) { "reactive-swift" } | ||
|
||
before { stub_upload_pack } | ||
|
||
describe "#can_update?" do | ||
subject { checker.can_update?(requirements_to_unlock: :own) } | ||
|
||
it { is_expected.to be_falsey } | ||
end | ||
|
||
describe "#latest_version" do | ||
subject { checker.latest_version } | ||
|
||
it { is_expected.to eq(dependency.version) } | ||
end | ||
|
||
describe "#latest_resolvable_version" do | ||
subject { checker.latest_resolvable_version } | ||
|
||
it { is_expected.to eq(dependency.version) } | ||
end | ||
end | ||
|
||
context "with a dependency that needs only lockfile changes to get updated" do | ||
let(:name) { "quick" } | ||
let(:url) { "https://github.com/Quick/Quick" } | ||
let(:upload_pack_fixture) { "quick" } | ||
|
||
before { stub_upload_pack } | ||
|
||
describe "#can_update?" do | ||
subject { checker.can_update?(requirements_to_unlock: :own) } | ||
|
||
it { is_expected.to be_truthy } | ||
end | ||
|
||
describe "#latest_version" do | ||
subject { checker.latest_version } | ||
|
||
it { is_expected.to eq("7.0.2") } | ||
end | ||
|
||
describe "#latest_resolvable_version" do | ||
subject { checker.latest_resolvable_version } | ||
|
||
it { is_expected.to eq("7.0.2") } | ||
end | ||
end | ||
|
||
context "with a dependency that needs manifest changes to get updated" do | ||
let(:name) { "nimble" } | ||
let(:url) { "https://github.com/Quick/Nimble" } | ||
let(:upload_pack_fixture) { "nimble" } | ||
|
||
before { stub_upload_pack } | ||
|
||
describe "#can_update?" do | ||
subject { checker.can_update?(requirements_to_unlock: :own) } | ||
|
||
it { is_expected.to be_truthy } | ||
end | ||
|
||
describe "#latest_version" do | ||
subject { checker.latest_version } | ||
|
||
it { is_expected.to eq("12.0.1") } | ||
end | ||
|
||
describe "#latest_resolvable_version" do | ||
subject { checker.latest_resolvable_version } | ||
|
||
it { is_expected.to eq("12.0.1") } | ||
end | ||
end | ||
end |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.