Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audit(github): prefer /archive/refs/tags urls over /archive #16126

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Library/Homebrew/rubocops/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@
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})."

Check warning on line 224 in Library/Homebrew/rubocops/urls.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/rubocops/urls.rb#L224

Added line #L224 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to write an autocorrect for this if possible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any example of doing autocorrect?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrector.replace(homepage_parameter_node.source_range, "\"#{homepage}/\"")

Can wait till a follow-up PR but, if it's not too hard: autocorrects are always nice to have.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

chenrui333 marked this conversation as resolved.
Show resolved Hide resolved
end

# Don't use GitHub .zip files
zip_gh_pattern = %r{https://.*github.*/(archive|releases)/.*\.zip$}
audit_urls(urls, zip_gh_pattern) do |_, url|
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/shared_audits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@

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)$})

Check warning on line 160 in Library/Homebrew/utils/shared_audits.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/shared_audits.rb#L160

Added line #L160 was not covered by tests
.to_a
.second
tag ||= url.match(%r{^https://github\.com/[\w-]+/[\w-]+/releases/download/([^/]+)/})
Expand Down