Merge pull request #16126 from chenrui333/github/use-new-archive-urls

audit(github): prefer `/archive/refs/tags` urls over `/archive`
This commit is contained in:
Bo Anderson 2023-10-24 18:48:03 +01:00 committed by GitHub
commit 141ac157fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -217,6 +217,13 @@ module RuboCop
problem "Use /archive/ URLs for GitHub tarballs (url is #{url})."
end
archive_ref_tags_gh_pattern = %r{https://.*github.*/archive/(?![a-fA-F0-9]{40})(?!refs/tags/).*\.tar\.gz$}
audit_urls(urls, archive_ref_tags_gh_pattern) do |_, url|
next if url.end_with?(".git")
problem "Use /archive/refs/tags URLs for GitHub tarballs (url is #{url})."
end
# Don't use GitHub .zip files
zip_gh_pattern = %r{https://.*github.*/(archive|releases)/.*\.zip$}
audit_urls(urls, zip_gh_pattern) do |_, url|

View File

@ -157,7 +157,7 @@ module SharedAudits
def github_tag_from_url(url)
url = url.to_s
tag = url.match(%r{^https://github\.com/[\w-]+/[\w-]+/archive/([^/]+)\.(tar\.gz|zip)$})
tag = url.match(%r{^https://github\.com/[\w-]+/[\w-]+/archive/refs/tags/([^/]+)\.(tar\.gz|zip)$})
.to_a
.second
tag ||= url.match(%r{^https://github\.com/[\w-]+/[\w-]+/releases/download/([^/]+)/})