diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 8f44e5030f..49a632c8de 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -468,8 +468,9 @@ module Cask user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if @online return if user.nil? - # TODO: Detect tag from URL instead of using `cask.version`. - error = SharedAudits.github_release(user, repo, cask.version, cask: cask) + tag = SharedAudits.github_tag_from_url(cask.url) + tag ||= cask.version + error = SharedAudits.github_release(user, repo, tag, cask: cask) add_error error if error end @@ -481,7 +482,9 @@ module Cask 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 end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 3cd43ca7e1..59c13f63e1 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -784,9 +784,7 @@ module Homebrew owner = Regexp.last_match(1) repo = Regexp.last_match(2) - tag = url.match(%r{^https://gitlab\.com/[\w-]+/[\w-]+/-/archive/([^/]+)/}) - .to_a - .second + tag = SharedAudits.gitlab_tag_from_url(url) tag ||= stable.specs[:tag] tag ||= stable.version @@ -797,12 +795,7 @@ module Homebrew when %r{^https://github.com/([\w-]+)/([\w-]+)} owner = Regexp.last_match(1) repo = Regexp.last_match(2) - 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 = SharedAudits.github_tag_from_url(url) tag ||= formula.stable.specs[:tag] if @online diff --git a/Library/Homebrew/utils/shared_audits.rb b/Library/Homebrew/utils/shared_audits.rb index 0feffa668f..dd28e8e4a9 100644 --- a/Library/Homebrew/utils/shared_audits.rb +++ b/Library/Homebrew/utils/shared_audits.rb @@ -164,4 +164,22 @@ module SharedAudits "Bitbucket repository not notable enough (<30 forks and <75 watchers)" 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