Skip to content
GitLab
菜单
项目
群组
代码片段
/
帮助
帮助
支持
社区论坛
快捷键
?
提交反馈
登录/注册
切换导航
菜单
打开侧边栏
KMSCAKKSCFKA AKFACAMADCAS
brew
提交
d9b7c207
未验证
提交
d9b7c207
编辑于
11月 29, 2021
作者:
Mike McQuaid
提交者:
GitHub
11月 29, 2021
浏览文件
Merge pull request #12476 from EricFromCanada/livecheck-homebrew-curl
livecheck: use brewed curl if called for by download URL
上级
32a3e1fe
ed3042c3
变更
5
Hide whitespace changes
Inline
Side-by-side
Library/Homebrew/livecheck/livecheck.rb
浏览文件 @
d9b7c207
...
...
@@ -529,6 +529,28 @@ module Homebrew
url
end
# Fetch with brewed curl if using the download or homepage URL
# and the download URL specifies `using: :homebrew_curl`.
sig
{
params
(
formula_or_cask:
T
.
any
(
Formula
,
Cask
::
Cask
),
url:
String
).
returns
(
T
::
Boolean
)
}
def
use_homebrew_curl?
(
formula_or_cask
,
url
)
if
checkable_urls
(
formula_or_cask
).
include?
(
url
)
case
formula_or_cask
when
Formula
[
:stable
,
:head
].
any?
do
|
spec_name
|
next
false
unless
(
spec
=
formula_or_cask
.
send
(
spec_name
))
spec
.
using
==
:homebrew_curl
end
when
Cask
::
Cask
formula_or_cask
.
url
.
using
==
:homebrew_curl
else
T
.
absurd
(
formula_or_cask
)
end
else
false
end
end
# Identifies the latest version of the formula and returns a Hash containing
# the version information. Returns nil if a latest version couldn't be found.
sig
{
...
...
@@ -637,10 +659,16 @@ module Homebrew
next
if
strategy
.
blank?
homebrew_curl
=
case
strategy_name
when
"PageMatch"
,
"HeaderMatch"
use_homebrew_curl?
((
referenced_formula_or_cask
||
formula_or_cask
),
url
)
end
strategy_data
=
strategy
.
find_versions
(
url:
url
,
regex:
livecheck_regex
,
cask:
cask
,
url:
url
,
regex:
livecheck_regex
,
homebrew_curl:
homebrew_curl
,
cask:
cask
,
&
livecheck_strategy_block
)
match_version_map
=
strategy_data
[
:matches
]
...
...
Library/Homebrew/livecheck/strategy.rb
浏览文件 @
d9b7c207
...
...
@@ -171,16 +171,18 @@ module Homebrew
# collected into an array of hashes.
#
# @param url [String] the URL to fetch
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
# @return [Array]
sig
{
params
(
url:
String
).
returns
(
T
::
Array
[
T
::
Hash
[
String
,
String
]])
}
def
self
.
page_headers
(
url
)
sig
{
params
(
url:
String
,
homebrew_curl:
T
::
Boolean
).
returns
(
T
::
Array
[
T
::
Hash
[
String
,
String
]])
}
def
self
.
page_headers
(
url
,
homebrew_curl:
false
)
headers
=
[]
[
:default
,
:browser
].
each
do
|
user_agent
|
stdout
,
_
,
status
=
curl_with_workarounds
(
*
PAGE_HEADERS_CURL_ARGS
,
url
,
**
DEFAULT_CURL_OPTIONS
,
user_agent:
user_agent
use_homebrew_curl:
homebrew_curl
,
user_agent:
user_agent
)
while
stdout
.
match?
(
/\AHTTP.*\r$/
)
...
...
@@ -203,9 +205,10 @@ module Homebrew
# array with the error message instead.
#
# @param url [String] the URL of the content to check
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
# @return [Hash]
sig
{
params
(
url:
String
).
returns
(
T
::
Hash
[
Symbol
,
T
.
untyped
])
}
def
self
.
page_content
(
url
)
sig
{
params
(
url:
String
,
homebrew_curl:
T
::
Boolean
).
returns
(
T
::
Hash
[
Symbol
,
T
.
untyped
])
}
def
self
.
page_content
(
url
,
homebrew_curl:
false
)
original_url
=
url
stderr
=
nil
...
...
@@ -213,7 +216,8 @@ module Homebrew
stdout
,
stderr
,
status
=
curl_with_workarounds
(
*
PAGE_CONTENT_CURL_ARGS
,
url
,
**
DEFAULT_CURL_OPTIONS
,
user_agent:
user_agent
use_homebrew_curl:
homebrew_curl
,
user_agent:
user_agent
)
next
unless
status
.
success?
...
...
Library/Homebrew/livecheck/strategy/header_match.rb
浏览文件 @
d9b7c207
...
...
@@ -71,19 +71,21 @@ module Homebrew
#
# @param url [String] the URL to fetch
# @param regex [Regexp, nil] a regex used for matching versions
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
# @return [Hash]
sig
{
params
(
url:
String
,
regex:
T
.
nilable
(
Regexp
),
_unused:
T
.
nilable
(
T
::
Hash
[
Symbol
,
T
.
untyped
]),
block:
T
.
untyped
,
url:
String
,
regex:
T
.
nilable
(
Regexp
),
homebrew_curl:
T
::
Boolean
,
_unused:
T
.
nilable
(
T
::
Hash
[
Symbol
,
T
.
untyped
]),
block:
T
.
untyped
,
).
returns
(
T
::
Hash
[
Symbol
,
T
.
untyped
])
}
def
self
.
find_versions
(
url
:,
regex:
nil
,
**
_unused
,
&
block
)
def
self
.
find_versions
(
url
:,
regex:
nil
,
homebrew_curl:
false
,
**
_unused
,
&
block
)
match_data
=
{
matches:
{},
regex:
regex
,
url:
url
}
headers
=
Strategy
.
page_headers
(
url
)
headers
=
Strategy
.
page_headers
(
url
,
homebrew_curl:
homebrew_curl
)
# Merge the headers from all responses into one hash
merged_headers
=
headers
.
reduce
(
&
:merge
)
...
...
Library/Homebrew/livecheck/strategy/page_match.rb
浏览文件 @
d9b7c207
...
...
@@ -79,17 +79,19 @@ module Homebrew
# @param regex [Regexp, nil] a regex used for matching versions
# @param provided_content [String, nil] page content to use in place of
# fetching via Strategy#page_content
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
# @return [Hash]
sig
{
params
(
url:
String
,
regex:
T
.
nilable
(
Regexp
),
provided_content:
T
.
nilable
(
String
),
homebrew_curl:
T
::
Boolean
,
_unused:
T
.
nilable
(
T
::
Hash
[
Symbol
,
T
.
untyped
]),
block:
T
.
untyped
,
).
returns
(
T
::
Hash
[
Symbol
,
T
.
untyped
])
}
def
self
.
find_versions
(
url
:,
regex:
nil
,
provided_content:
nil
,
**
_unused
,
&
block
)
def
self
.
find_versions
(
url
:,
regex:
nil
,
provided_content:
nil
,
homebrew_curl:
false
,
**
_unused
,
&
block
)
if
regex
.
blank?
&&
block
.
blank?
raise
ArgumentError
,
"
#{
T
.
must
(
name
).
demodulize
}
requires a regex or `strategy` block"
end
...
...
@@ -101,7 +103,7 @@ module Homebrew
match_data
[
:cached
]
=
true
provided_content
else
match_data
.
merge!
(
Strategy
.
page_content
(
url
))
match_data
.
merge!
(
Strategy
.
page_content
(
url
,
homebrew_curl:
homebrew_curl
))
match_data
[
:content
]
end
return
match_data
if
content
.
blank?
...
...
Library/Homebrew/test/livecheck/livecheck_spec.rb
浏览文件 @
d9b7c207
...
...
@@ -16,7 +16,7 @@ describe Homebrew::Livecheck do
formula
(
"test"
)
do
desc
"Test formula"
homepage
"https://brew.sh"
url
"https://brew.sh/test-0.0.1.tgz"
url
"https://brew.sh/test-0.0.1.tgz"
,
using: :homebrew_curl
head
"https://github.com/Homebrew/brew.git"
livecheck
do
...
...
@@ -31,7 +31,7 @@ describe Homebrew::Livecheck do
cask "test" do
version "0.0.1,2"
url "https://brew.sh/test-0.0.1.dmg"
url "https://brew.sh/test-0.0.1.dmg"
, using: :homebrew_curl
name "Test"
desc "Test cask"
homepage "https://brew.sh"
...
...
@@ -147,6 +147,17 @@ describe Homebrew::Livecheck do
end
end
describe
"::use_homebrew_curl?"
do
it
"uses brewed curl if called for by the download URL"
do
expect
(
livecheck
.
use_homebrew_curl?
(
f
,
livecheck_url
)).
to
be
(
false
)
expect
(
livecheck
.
use_homebrew_curl?
(
f
,
homepage_url
)).
to
be
(
true
)
expect
(
livecheck
.
use_homebrew_curl?
(
f
,
stable_url
)).
to
be
(
true
)
expect
(
livecheck
.
use_homebrew_curl?
(
c
,
livecheck_url
)).
to
be
(
false
)
expect
(
livecheck
.
use_homebrew_curl?
(
c
,
homepage_url
)).
to
be
(
true
)
expect
(
livecheck
.
use_homebrew_curl?
(
c
,
cask_url
)).
to
be
(
true
)
end
end
describe
"::preprocess_url"
do
let
(
:github_git_url_with_extension
)
{
"https://github.com/Homebrew/brew.git"
}
...
...
编辑
预览
支持
Markdown
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录