Merge pull request #17632 from samford/livecheck/expand-typed-strict
This commit is contained in:
commit
315437c01d
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "livecheck/constants"
|
require "livecheck/constants"
|
||||||
@ -22,15 +22,15 @@ class Livecheck
|
|||||||
sig { params(package_or_resource: T.any(Cask::Cask, T.class_of(Formula), Resource)).void }
|
sig { params(package_or_resource: T.any(Cask::Cask, T.class_of(Formula), Resource)).void }
|
||||||
def initialize(package_or_resource)
|
def initialize(package_or_resource)
|
||||||
@package_or_resource = package_or_resource
|
@package_or_resource = package_or_resource
|
||||||
@referenced_cask_name = nil
|
@referenced_cask_name = T.let(nil, T.nilable(String))
|
||||||
@referenced_formula_name = nil
|
@referenced_formula_name = T.let(nil, T.nilable(String))
|
||||||
@regex = nil
|
@regex = T.let(nil, T.nilable(Regexp))
|
||||||
@skip = false
|
@skip = T.let(false, T::Boolean)
|
||||||
@skip_msg = nil
|
@skip_msg = T.let(nil, T.nilable(String))
|
||||||
@strategy = nil
|
@strategy = T.let(nil, T.nilable(Symbol))
|
||||||
@strategy_block = nil
|
@strategy_block = T.let(nil, T.nilable(Proc))
|
||||||
@throttle = nil
|
@throttle = T.let(nil, T.nilable(Integer))
|
||||||
@url = nil
|
@url = T.let(nil, T.any(NilClass, String, Symbol))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the `@referenced_cask_name` instance variable to the provided `String`
|
# Sets the `@referenced_cask_name` instance variable to the provided `String`
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
@ -14,7 +14,7 @@ module Homebrew
|
|||||||
livecheckable: T::Boolean,
|
livecheckable: T::Boolean,
|
||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def package_or_resource_skip(package_or_resource, livecheckable, full_name: false, verbose: false)
|
def package_or_resource_skip(package_or_resource, livecheckable, full_name: false, verbose: false)
|
||||||
formula = package_or_resource if package_or_resource.is_a?(Formula)
|
formula = package_or_resource if package_or_resource.is_a?(Formula)
|
||||||
@ -51,7 +51,7 @@ module Homebrew
|
|||||||
_livecheckable: T::Boolean,
|
_livecheckable: T::Boolean,
|
||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def formula_head_only(formula, _livecheckable, full_name: false, verbose: false)
|
def formula_head_only(formula, _livecheckable, full_name: false, verbose: false)
|
||||||
return {} if !formula.head_only? || formula.any_version_installed?
|
return {} if !formula.head_only? || formula.any_version_installed?
|
||||||
@ -71,7 +71,7 @@ module Homebrew
|
|||||||
livecheckable: T::Boolean,
|
livecheckable: T::Boolean,
|
||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def formula_deprecated(formula, livecheckable, full_name: false, verbose: false)
|
def formula_deprecated(formula, livecheckable, full_name: false, verbose: false)
|
||||||
return {} if !formula.deprecated? || livecheckable
|
return {} if !formula.deprecated? || livecheckable
|
||||||
@ -85,7 +85,7 @@ module Homebrew
|
|||||||
livecheckable: T::Boolean,
|
livecheckable: T::Boolean,
|
||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def formula_disabled(formula, livecheckable, full_name: false, verbose: false)
|
def formula_disabled(formula, livecheckable, full_name: false, verbose: false)
|
||||||
return {} if !formula.disabled? || livecheckable
|
return {} if !formula.disabled? || livecheckable
|
||||||
@ -99,7 +99,7 @@ module Homebrew
|
|||||||
livecheckable: T::Boolean,
|
livecheckable: T::Boolean,
|
||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def formula_versioned(formula, livecheckable, full_name: false, verbose: false)
|
def formula_versioned(formula, livecheckable, full_name: false, verbose: false)
|
||||||
return {} if !formula.versioned_formula? || livecheckable
|
return {} if !formula.versioned_formula? || livecheckable
|
||||||
@ -113,7 +113,7 @@ module Homebrew
|
|||||||
livecheckable: T::Boolean,
|
livecheckable: T::Boolean,
|
||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def cask_deprecated(cask, livecheckable, full_name: false, verbose: false)
|
def cask_deprecated(cask, livecheckable, full_name: false, verbose: false)
|
||||||
return {} if !cask.deprecated? || livecheckable
|
return {} if !cask.deprecated? || livecheckable
|
||||||
@ -127,7 +127,7 @@ module Homebrew
|
|||||||
livecheckable: T::Boolean,
|
livecheckable: T::Boolean,
|
||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def cask_disabled(cask, livecheckable, full_name: false, verbose: false)
|
def cask_disabled(cask, livecheckable, full_name: false, verbose: false)
|
||||||
return {} if !cask.disabled? || livecheckable
|
return {} if !cask.disabled? || livecheckable
|
||||||
@ -142,7 +142,7 @@ module Homebrew
|
|||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
extract_plist: T::Boolean,
|
extract_plist: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def cask_extract_plist(cask, _livecheckable, full_name: false, verbose: false, extract_plist: false)
|
def cask_extract_plist(cask, _livecheckable, full_name: false, verbose: false, extract_plist: false)
|
||||||
return {} if extract_plist || cask.livecheck.strategy != :extract_plist
|
return {} if extract_plist || cask.livecheck.strategy != :extract_plist
|
||||||
@ -162,7 +162,7 @@ module Homebrew
|
|||||||
livecheckable: T::Boolean,
|
livecheckable: T::Boolean,
|
||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def cask_version_latest(cask, livecheckable, full_name: false, verbose: false)
|
def cask_version_latest(cask, livecheckable, full_name: false, verbose: false)
|
||||||
return {} if !(cask.present? && cask.version&.latest?) || livecheckable
|
return {} if !(cask.present? && cask.version&.latest?) || livecheckable
|
||||||
@ -176,7 +176,7 @@ module Homebrew
|
|||||||
livecheckable: T::Boolean,
|
livecheckable: T::Boolean,
|
||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false)
|
def cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false)
|
||||||
return {} if !(cask.present? && cask.url&.unversioned?) || livecheckable
|
return {} if !(cask.present? && cask.url&.unversioned?) || livecheckable
|
||||||
@ -185,28 +185,28 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Skip conditions for formulae.
|
# Skip conditions for formulae.
|
||||||
FORMULA_CHECKS = [
|
FORMULA_CHECKS = T.let([
|
||||||
:package_or_resource_skip,
|
:package_or_resource_skip,
|
||||||
:formula_head_only,
|
:formula_head_only,
|
||||||
:formula_deprecated,
|
:formula_deprecated,
|
||||||
:formula_disabled,
|
:formula_disabled,
|
||||||
:formula_versioned,
|
:formula_versioned,
|
||||||
].freeze
|
].freeze, T::Array[Symbol])
|
||||||
|
|
||||||
# Skip conditions for casks.
|
# Skip conditions for casks.
|
||||||
CASK_CHECKS = [
|
CASK_CHECKS = T.let([
|
||||||
:package_or_resource_skip,
|
:package_or_resource_skip,
|
||||||
:cask_deprecated,
|
:cask_deprecated,
|
||||||
:cask_disabled,
|
:cask_disabled,
|
||||||
:cask_extract_plist,
|
:cask_extract_plist,
|
||||||
:cask_version_latest,
|
:cask_version_latest,
|
||||||
:cask_url_unversioned,
|
:cask_url_unversioned,
|
||||||
].freeze
|
].freeze, T::Array[Symbol])
|
||||||
|
|
||||||
# Skip conditions for resources.
|
# Skip conditions for resources.
|
||||||
RESOURCE_CHECKS = [
|
RESOURCE_CHECKS = T.let([
|
||||||
:package_or_resource_skip,
|
:package_or_resource_skip,
|
||||||
].freeze
|
].freeze, T::Array[Symbol])
|
||||||
|
|
||||||
# If a formula/cask/resource should be skipped, we return a hash from
|
# If a formula/cask/resource should be skipped, we return a hash from
|
||||||
# `Livecheck#status_hash`, which contains a `status` type and sometimes
|
# `Livecheck#status_hash`, which contains a `status` type and sometimes
|
||||||
@ -217,7 +217,7 @@ module Homebrew
|
|||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
extract_plist: T::Boolean,
|
extract_plist: T::Boolean,
|
||||||
).returns(Hash)
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def skip_information(package_or_resource, full_name: false, verbose: false, extract_plist: true)
|
def skip_information(package_or_resource, full_name: false, verbose: false, extract_plist: true)
|
||||||
livecheckable = package_or_resource.livecheckable?
|
livecheckable = package_or_resource.livecheckable?
|
||||||
@ -255,7 +255,7 @@ module Homebrew
|
|||||||
full_name: T::Boolean,
|
full_name: T::Boolean,
|
||||||
verbose: T::Boolean,
|
verbose: T::Boolean,
|
||||||
extract_plist: T::Boolean,
|
extract_plist: T::Boolean,
|
||||||
).returns(T.nilable(Hash))
|
).returns(T.nilable(T::Hash[Symbol, T.untyped]))
|
||||||
}
|
}
|
||||||
def referenced_skip_information(
|
def referenced_skip_information(
|
||||||
livecheck_package_or_resource,
|
livecheck_package_or_resource,
|
||||||
@ -298,7 +298,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Prints default livecheck output in relation to skip conditions.
|
# Prints default livecheck output in relation to skip conditions.
|
||||||
sig { params(skip_hash: Hash).void }
|
sig { params(skip_hash: T::Hash[Symbol, T.untyped]).void }
|
||||||
def print_skip_information(skip_hash)
|
def print_skip_information(skip_hash)
|
||||||
return unless skip_hash.is_a?(Hash)
|
return unless skip_hash.is_a?(Hash)
|
||||||
|
|
||||||
|
@ -25,13 +25,13 @@ module Homebrew
|
|||||||
|
|
||||||
# cURL does not set a default `--max-time` value, so we provide a value
|
# cURL does not set a default `--max-time` value, so we provide a value
|
||||||
# to ensure cURL will time out in a reasonable amount of time.
|
# to ensure cURL will time out in a reasonable amount of time.
|
||||||
CURL_MAX_TIME = CURL_CONNECT_TIMEOUT + 5
|
CURL_MAX_TIME = T.let(CURL_CONNECT_TIMEOUT + 5, Integer)
|
||||||
|
|
||||||
# The `curl` process will sometimes hang indefinitely (despite setting
|
# The `curl` process will sometimes hang indefinitely (despite setting
|
||||||
# the `--max-time` argument) and it needs to be quit for livecheck to
|
# the `--max-time` argument) and it needs to be quit for livecheck to
|
||||||
# continue. This value is used to set the `timeout` argument on
|
# continue. This value is used to set the `timeout` argument on
|
||||||
# `Utils::Curl` method calls in {Strategy}.
|
# `Utils::Curl` method calls in {Strategy}.
|
||||||
CURL_PROCESS_TIMEOUT = CURL_MAX_TIME + 5
|
CURL_PROCESS_TIMEOUT = T.let(CURL_MAX_TIME + 5, Integer)
|
||||||
|
|
||||||
# The maximum number of redirections that `curl` should allow.
|
# The maximum number of redirections that `curl` should allow.
|
||||||
MAX_REDIRECTIONS = 5
|
MAX_REDIRECTIONS = 5
|
||||||
@ -41,20 +41,20 @@ module Homebrew
|
|||||||
# number of responses in this context. The `+ 1` here accounts for the
|
# number of responses in this context. The `+ 1` here accounts for the
|
||||||
# situation where there are exactly `MAX_REDIRECTIONS` number of
|
# situation where there are exactly `MAX_REDIRECTIONS` number of
|
||||||
# redirections, followed by a final `200 OK` response.
|
# redirections, followed by a final `200 OK` response.
|
||||||
MAX_PARSE_ITERATIONS = MAX_REDIRECTIONS + 1
|
MAX_PARSE_ITERATIONS = T.let(MAX_REDIRECTIONS + 1, Integer)
|
||||||
|
|
||||||
# Baseline `curl` arguments used in {Strategy} methods.
|
# Baseline `curl` arguments used in {Strategy} methods.
|
||||||
DEFAULT_CURL_ARGS = [
|
DEFAULT_CURL_ARGS = T.let([
|
||||||
# Follow redirections to handle mirrors, relocations, etc.
|
# Follow redirections to handle mirrors, relocations, etc.
|
||||||
"--location",
|
"--location",
|
||||||
"--max-redirs", MAX_REDIRECTIONS.to_s,
|
"--max-redirs", MAX_REDIRECTIONS.to_s,
|
||||||
# Avoid progress bar text, so we can reliably identify `curl` error
|
# Avoid progress bar text, so we can reliably identify `curl` error
|
||||||
# messages in output
|
# messages in output
|
||||||
"--silent"
|
"--silent"
|
||||||
].freeze
|
].freeze, T::Array[String])
|
||||||
|
|
||||||
# `curl` arguments used in `Strategy#page_content` method.
|
# `curl` arguments used in `Strategy#page_content` method.
|
||||||
PAGE_CONTENT_CURL_ARGS = ([
|
PAGE_CONTENT_CURL_ARGS = T.let(([
|
||||||
"--compressed",
|
"--compressed",
|
||||||
# Return an error when the HTTP response code is 400 or greater but
|
# Return an error when the HTTP response code is 400 or greater but
|
||||||
# continue to return body content
|
# continue to return body content
|
||||||
@ -62,10 +62,10 @@ module Homebrew
|
|||||||
# Include HTTP response headers in output, so we can identify the
|
# Include HTTP response headers in output, so we can identify the
|
||||||
# final URL after any redirections
|
# final URL after any redirections
|
||||||
"--include",
|
"--include",
|
||||||
] + DEFAULT_CURL_ARGS).freeze
|
] + DEFAULT_CURL_ARGS).freeze, T::Array[String])
|
||||||
|
|
||||||
# Baseline `curl` options used in {Strategy} methods.
|
# Baseline `curl` options used in {Strategy} methods.
|
||||||
DEFAULT_CURL_OPTIONS = {
|
DEFAULT_CURL_OPTIONS = T.let({
|
||||||
print_stdout: false,
|
print_stdout: false,
|
||||||
print_stderr: false,
|
print_stderr: false,
|
||||||
debug: false,
|
debug: false,
|
||||||
@ -74,7 +74,7 @@ module Homebrew
|
|||||||
connect_timeout: CURL_CONNECT_TIMEOUT,
|
connect_timeout: CURL_CONNECT_TIMEOUT,
|
||||||
max_time: CURL_MAX_TIME,
|
max_time: CURL_MAX_TIME,
|
||||||
retries: 0,
|
retries: 0,
|
||||||
}.freeze
|
}.freeze, T::Hash[Symbol, T.untyped])
|
||||||
|
|
||||||
# A regex used to identify a tarball extension at the end of a string.
|
# A regex used to identify a tarball extension at the end of a string.
|
||||||
TARBALL_EXTENSION_REGEX = /
|
TARBALL_EXTENSION_REGEX = /
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
@ -23,14 +23,17 @@ module Homebrew
|
|||||||
|
|
||||||
# The default `strategy` block used to extract version information when
|
# The default `strategy` block used to extract version information when
|
||||||
# a `strategy` block isn't provided.
|
# a `strategy` block isn't provided.
|
||||||
DEFAULT_BLOCK = proc do |json, regex|
|
DEFAULT_BLOCK = T.let(proc do |json, regex|
|
||||||
json["versions"]&.map do |version|
|
json["versions"]&.map do |version|
|
||||||
next if version["yanked"]
|
next if version["yanked"]
|
||||||
next unless (match = version["num"]&.match(regex))
|
next unless (match = version["num"]&.match(regex))
|
||||||
|
|
||||||
match[1]
|
match[1]
|
||||||
end
|
end
|
||||||
end.freeze
|
end.freeze, T.proc.params(
|
||||||
|
arg0: T::Hash[String, T.untyped],
|
||||||
|
arg1: Regexp,
|
||||||
|
).returns(T.any(String, T::Array[String])))
|
||||||
|
|
||||||
# The `Regexp` used to determine if the strategy applies to the URL.
|
# The `Regexp` used to determine if the strategy applies to the URL.
|
||||||
URL_MATCH_REGEX = %r{
|
URL_MATCH_REGEX = %r{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
@ -50,7 +50,7 @@ module Homebrew
|
|||||||
# Keys in the release JSON that could contain the version.
|
# Keys in the release JSON that could contain the version.
|
||||||
# The tag name is checked first, to better align with the {Git}
|
# The tag name is checked first, to better align with the {Git}
|
||||||
# strategy.
|
# strategy.
|
||||||
VERSION_KEYS = ["tag_name", "name"].freeze
|
VERSION_KEYS = T.let(["tag_name", "name"].freeze, T::Array[String])
|
||||||
|
|
||||||
# Whether the strategy can be applied to the provided URL.
|
# Whether the strategy can be applied to the provided URL.
|
||||||
#
|
#
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
@ -20,7 +20,7 @@ module Homebrew
|
|||||||
URL_MATCH_REGEX = %r{^https?://}i
|
URL_MATCH_REGEX = %r{^https?://}i
|
||||||
|
|
||||||
# The header fields to check when a `strategy` block isn't provided.
|
# The header fields to check when a `strategy` block isn't provided.
|
||||||
DEFAULT_HEADERS_TO_CHECK = ["content-disposition", "location"].freeze
|
DEFAULT_HEADERS_TO_CHECK = T.let(["content-disposition", "location"].freeze, T::Array[String])
|
||||||
|
|
||||||
# Whether the strategy can be applied to the provided URL.
|
# Whether the strategy can be applied to the provided URL.
|
||||||
#
|
#
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "bundle_version"
|
require "bundle_version"
|
||||||
@ -20,7 +20,7 @@ module Homebrew
|
|||||||
URL_MATCH_REGEX = %r{^https?://}i
|
URL_MATCH_REGEX = %r{^https?://}i
|
||||||
|
|
||||||
# Common `os` values used in appcasts to refer to macOS.
|
# Common `os` values used in appcasts to refer to macOS.
|
||||||
APPCAST_MACOS_STRINGS = ["macos", "osx"].freeze
|
APPCAST_MACOS_STRINGS = T.let(["macos", "osx"].freeze, T::Array[String])
|
||||||
|
|
||||||
# Whether the strategy can be applied to the provided URL.
|
# Whether the strategy can be applied to the provided URL.
|
||||||
#
|
#
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
@ -56,7 +56,7 @@ module Homebrew
|
|||||||
|
|
||||||
# Used to cache page content, so we don't fetch the same pages
|
# Used to cache page content, so we don't fetch the same pages
|
||||||
# repeatedly.
|
# repeatedly.
|
||||||
@page_data = {}
|
@page_data = T.let({}, T::Hash[String, String])
|
||||||
|
|
||||||
# Whether the strategy can be applied to the provided URL.
|
# Whether the strategy can be applied to the provided URL.
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user