Bitbucket: Fix tag match

The `Bitbucket` strategy currently matches versions from tag
tarball links on a project's `downloads/?tab=tags` page. It appears
that Bitbucket now uses a hash as the filename on this page instead
of the tag name, so the existing regex no longer matches.

This adds an alternative regex to match versions from the tag name
element (e.g., `<td class="name">example-1.2.3</td>`), which will fix
version matching in this scenario.
This commit is contained in:
Sam Ford 2023-05-19 10:51:49 -04:00
parent e85016230e
commit ba7cf9df7a
No known key found for this signature in database
GPG Key ID: 7AF5CBEE1DD6F76D
2 changed files with 21 additions and 16 deletions

View File

@ -61,24 +61,29 @@ module Homebrew
match = url.match(URL_MATCH_REGEX) match = url.match(URL_MATCH_REGEX)
return values if match.blank? return values if match.blank?
regex_prefix = Regexp.escape(T.must(match[:prefix])).gsub("\\-", "-")
# `/get/` archives are Git tag snapshots, so we need to check that tab # `/get/` archives are Git tag snapshots, so we need to check that tab
# instead of the main `/downloads/` page # instead of the main `/downloads/` page
values[:url] = if match[:dl_type] == "get" if match[:dl_type] == "get"
"https://bitbucket.org/#{match[:path]}/downloads/?tab=tags" values[:url] = "https://bitbucket.org/#{match[:path]}/downloads/?tab=tags"
else
"https://bitbucket.org/#{match[:path]}/downloads/"
end
regex_prefix = Regexp.escape(T.must(match[:prefix])).gsub("\\-", "-") # Example tag regexes:
# * `/<td[^>]*?class="name"[^>]*?>\s*v?(\d+(?:\.\d+)+)\s*?</im`
# * `/<td[^>]*?class="name"[^>]*?>\s*abc-v?(\d+(?:\.\d+)+)\s*?</im`
values[:regex] = /<td[^>]*?class="name"[^>]*?>\s*#{regex_prefix}v?(\d+(?:\.\d+)+)\s*?</im
else
values[:url] = "https://bitbucket.org/#{match[:path]}/downloads/"
# Use `\.t` instead of specific tarball extensions (e.g. .tar.gz) # Use `\.t` instead of specific tarball extensions (e.g. .tar.gz)
suffix = T.must(match[:suffix]).sub(Strategy::TARBALL_EXTENSION_REGEX, ".t") suffix = T.must(match[:suffix]).sub(Strategy::TARBALL_EXTENSION_REGEX, ".t")
regex_suffix = Regexp.escape(suffix).gsub("\\-", "-") regex_suffix = Regexp.escape(suffix).gsub("\\-", "-")
# Example regexes: # Example file regexes:
# * `/href=.*?v?(\d+(?:\.\d+)+)\.t/i` # * `/href=.*?v?(\d+(?:\.\d+)+)\.t/i`
# * `/href=.*?example-v?(\d+(?:\.\d+)+)\.t/i` # * `/href=.*?abc-v?(\d+(?:\.\d+)+)\.t/i`
values[:regex] = /href=.*?#{regex_prefix}v?(\d+(?:\.\d+)+)#{regex_suffix}/i values[:regex] = /href=.*?#{regex_prefix}v?(\d+(?:\.\d+)+)#{regex_suffix}/i
end
values values
end end

View File

@ -17,7 +17,7 @@ describe Homebrew::Livecheck::Strategy::Bitbucket do
{ {
get: { get: {
url: "https://bitbucket.org/abc/def/downloads/?tab=tags", url: "https://bitbucket.org/abc/def/downloads/?tab=tags",
regex: /href=.*?v?(\d+(?:\.\d+)+)\.t/i, regex: /<td[^>]*?class="name"[^>]*?>\s*v?(\d+(?:\.\d+)+)\s*?</im,
}, },
downloads: { downloads: {
url: "https://bitbucket.org/abc/def/downloads/", url: "https://bitbucket.org/abc/def/downloads/",