Merge pull request #14500 from MikeMcQuaid/remove_api_versions
api/versions: remove.
This commit is contained in:
commit
082e75e692
@ -4,7 +4,6 @@
|
|||||||
require "api/analytics"
|
require "api/analytics"
|
||||||
require "api/cask"
|
require "api/cask"
|
||||||
require "api/formula"
|
require "api/formula"
|
||||||
require "api/versions"
|
|
||||||
require "extend/cachable"
|
require "extend/cachable"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
|
|||||||
@ -1,47 +0,0 @@
|
|||||||
# typed: true
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module Homebrew
|
|
||||||
module API
|
|
||||||
# Helper functions for using the versions JSON API.
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
module Versions
|
|
||||||
class << self
|
|
||||||
extend T::Sig
|
|
||||||
|
|
||||||
def formulae
|
|
||||||
# The result is cached by Homebrew::API.fetch
|
|
||||||
Homebrew::API.fetch "versions-formulae.json"
|
|
||||||
end
|
|
||||||
|
|
||||||
def casks
|
|
||||||
# The result is cached by Homebrew::API.fetch
|
|
||||||
Homebrew::API.fetch "versions-casks.json"
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { params(name: String).returns(T.nilable(PkgVersion)) }
|
|
||||||
def latest_formula_version(name)
|
|
||||||
versions = formulae
|
|
||||||
return unless versions.key? name
|
|
||||||
|
|
||||||
version = Version.new(versions[name]["version"])
|
|
||||||
revision = versions[name]["revision"]
|
|
||||||
PkgVersion.new(version, revision)
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { params(token: String).returns(T.nilable(Version)) }
|
|
||||||
def latest_cask_version(token)
|
|
||||||
return unless casks.key? token
|
|
||||||
|
|
||||||
version = if casks[token]["versions"].key? MacOS.version.to_sym.to_s
|
|
||||||
casks[token]["versions"][MacOS.version.to_sym.to_s]
|
|
||||||
else
|
|
||||||
casks[token]["version"]
|
|
||||||
end
|
|
||||||
Version.new(version)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -4394,10 +4394,6 @@ module Homebrew::API::Formula
|
|||||||
extend ::T::Private::Methods::SingletonMethodHooks
|
extend ::T::Private::Methods::SingletonMethodHooks
|
||||||
end
|
end
|
||||||
|
|
||||||
module Homebrew::API::Versions
|
|
||||||
extend ::T::Private::Methods::SingletonMethodHooks
|
|
||||||
end
|
|
||||||
|
|
||||||
class Homebrew::CLI::Args
|
class Homebrew::CLI::Args
|
||||||
extend ::T::Private::Methods::MethodHooks
|
extend ::T::Private::Methods::MethodHooks
|
||||||
extend ::T::Private::Methods::SingletonMethodHooks
|
extend ::T::Private::Methods::SingletonMethodHooks
|
||||||
|
|||||||
@ -1,72 +0,0 @@
|
|||||||
# typed: false
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require "api"
|
|
||||||
|
|
||||||
describe Homebrew::API::Versions do
|
|
||||||
def mock_curl_output(stdout: "", success: true)
|
|
||||||
curl_output = OpenStruct.new(stdout: stdout, success?: success)
|
|
||||||
allow(Utils::Curl).to receive(:curl_output).and_return curl_output
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "::latest_formula_version" do
|
|
||||||
let(:versions_formulae_json) {
|
|
||||||
<<~EOS
|
|
||||||
{
|
|
||||||
"foo":{"version":"1.2.3","revision":0},
|
|
||||||
"bar":{"version":"1.2","revision":4}
|
|
||||||
}
|
|
||||||
EOS
|
|
||||||
}
|
|
||||||
|
|
||||||
it "returns the expected `PkgVersion` when the revision is 0" do
|
|
||||||
mock_curl_output stdout: versions_formulae_json
|
|
||||||
pkg_version = described_class.latest_formula_version("foo")
|
|
||||||
expect(pkg_version.to_s).to eq "1.2.3"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the expected `PkgVersion` when the revision is not 0" do
|
|
||||||
mock_curl_output stdout: versions_formulae_json
|
|
||||||
pkg_version = described_class.latest_formula_version("bar")
|
|
||||||
expect(pkg_version.to_s).to eq "1.2_4"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns `nil` when the formula is not in the JSON file" do
|
|
||||||
mock_curl_output stdout: versions_formulae_json
|
|
||||||
pkg_version = described_class.latest_formula_version("baz")
|
|
||||||
expect(pkg_version).to be_nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "::latest_cask_version", :needs_macos do
|
|
||||||
let(:versions_casks_json) {
|
|
||||||
<<~EOS
|
|
||||||
{
|
|
||||||
"foo":{"version":"1.2.3","versions":{}},
|
|
||||||
"bar":{"version":"1.2.3","versions":{"#{MacOS.version.to_sym}":"1.2.0"}},
|
|
||||||
"baz":{"version":"1.2.3","versions":{"test_os":"1.2.0"}}
|
|
||||||
}
|
|
||||||
EOS
|
|
||||||
}
|
|
||||||
|
|
||||||
it "returns the expected `Version`" do
|
|
||||||
mock_curl_output stdout: versions_casks_json
|
|
||||||
version = described_class.latest_cask_version("foo")
|
|
||||||
expect(version.to_s).to eq "1.2.3"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the expected `Version` for an OS with a non-default version" do
|
|
||||||
mock_curl_output stdout: versions_casks_json
|
|
||||||
version = described_class.latest_cask_version("bar")
|
|
||||||
expect(version.to_s).to eq "1.2.0"
|
|
||||||
version = described_class.latest_cask_version("baz")
|
|
||||||
expect(version.to_s).to eq "1.2.3"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns `nil` when the cask is not in the JSON file" do
|
|
||||||
mock_curl_output stdout: versions_casks_json
|
|
||||||
version = described_class.latest_cask_version("doesnotexist")
|
|
||||||
expect(version).to be_nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
x
Reference in New Issue
Block a user