cask/audit: detect tag from URL

This commit is contained in:
Seeker 2020-09-09 08:57:56 -07:00
parent 21e05e2c1d
commit e0645f3950
3 changed files with 26 additions and 12 deletions

View File

@ -468,8 +468,9 @@ module Cask
user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if @online user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if @online
return if user.nil? return if user.nil?
# TODO: Detect tag from URL instead of using `cask.version`. tag = SharedAudits.github_tag_from_url(cask.url)
error = SharedAudits.github_release(user, repo, cask.version, cask: cask) tag ||= cask.version
error = SharedAudits.github_release(user, repo, tag, cask: cask)
add_error error if error add_error error if error
end end
@ -481,7 +482,9 @@ module Cask
odebug "Auditing GitLab prerelease" odebug "Auditing GitLab prerelease"
error = SharedAudits.gitlab_release(user, repo, cask.version) tag = SharedAudits.gitlab_tag_from_url(cask.url)
tag ||= cask.version
error = SharedAudits.gitlab_release(user, repo, tag)
add_error error if error add_error error if error
end end

View File

@ -784,9 +784,7 @@ module Homebrew
owner = Regexp.last_match(1) owner = Regexp.last_match(1)
repo = Regexp.last_match(2) repo = Regexp.last_match(2)
tag = url.match(%r{^https://gitlab\.com/[\w-]+/[\w-]+/-/archive/([^/]+)/}) tag = SharedAudits.gitlab_tag_from_url(url)
.to_a
.second
tag ||= stable.specs[:tag] tag ||= stable.specs[:tag]
tag ||= stable.version tag ||= stable.version
@ -797,12 +795,7 @@ module Homebrew
when %r{^https://github.com/([\w-]+)/([\w-]+)} when %r{^https://github.com/([\w-]+)/([\w-]+)}
owner = Regexp.last_match(1) owner = Regexp.last_match(1)
repo = Regexp.last_match(2) repo = Regexp.last_match(2)
tag = url.match(%r{^https://github\.com/[\w-]+/[\w-]+/archive/([^/]+)\.(tar\.gz|zip)$}) tag = SharedAudits.github_tag_from_url(url)
.to_a
.second
tag ||= url.match(%r{^https://github\.com/[\w-]+/[\w-]+/releases/download/([^/]+)/})
.to_a
.second
tag ||= formula.stable.specs[:tag] tag ||= formula.stable.specs[:tag]
if @online if @online

View File

@ -164,4 +164,22 @@ module SharedAudits
"Bitbucket repository not notable enough (<30 forks and <75 watchers)" "Bitbucket repository not notable enough (<30 forks and <75 watchers)"
end end
def github_tag_from_url(url)
url = url.to_s
tag = url.match(%r{^https://github\.com/[\w-]+/[\w-]+/archive/([^/]+)\.(tar\.gz|zip)$})
.to_a
.second
tag ||= url.match(%r{^https://github\.com/[\w-]+/[\w-]+/releases/download/([^/]+)/})
.to_a
.second
tag
end
def gitlab_tag_from_url(url)
url = url.to_s
url.match(%r{^https://gitlab\.com/[\w-]+/[\w-]+/-/archive/([^/]+)/})
.to_a
.second
end
end end