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

Checks GitHub API if homepage 404s during brew audit --online #13907

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
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def check_https_availability

return unless cask.homepage

validate_url_for_https_availability(cask.homepage, "homepage URL", cask.token, cask.tap,
validate_url_for_https_availability(cask.homepage, SharedAudits::URL_TYPE_HOMEPAGE, cask.token, cask.tap,
user_agents: [:browser, :default],
check_content: true,
strict: strict?)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def audit_homepage
end

if (http_content_problem = curl_check_http_content(homepage,
"homepage URL",
SharedAudits::URL_TYPE_HOMEPAGE,
user_agents: [:browser, :default],
check_content: true,
strict: @strict,
Expand Down
20 changes: 19 additions & 1 deletion Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,25 @@ def curl_check_http_content(url, url_type, specs: {}, user_agents: [:default],
url_protected_by_cloudflare?(response) || url_protected_by_incapsula?(response)
end

return "The #{url_type} #{url} is not reachable (HTTP status code #{details[:status_code]})"
# https://github.com/Homebrew/brew/issues/13789
# If the `:homepage` of a formula is private, it will fail an `audit`
# since there's no way to specify a `strategy` with `using:` and
# GitHub does not authorize access to the web UI using token
#
# Strategy:
# If the `:homepage` 404s, it's a GitHub link, and we have a token then
# check the API (which does use tokens) for the repository
repo_details = url.match(%r{https?://github\.com/(?<user>[^/]+)/(?<repo>[^/]+)/?.*})
check_github_api = url_type == SharedAudits::URL_TYPE_HOMEPAGE &&
details[:status_code] == "404" &&
repo_details &&
Homebrew::EnvConfig.github_api_token

unless check_github_api
return "The #{url_type} #{url} is not reachable (HTTP status code #{details[:status_code]})"
end

"Unable to find homepage" if SharedAudits.github_repo_data(repo_details[:user], repo_details[:repo]).nil?
end

if url.start_with?("https://") && Homebrew::EnvConfig.no_insecure_redirect? &&
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/utils/shared_audits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module SharedAudits
include Utils::Curl
extend Utils::Curl

URL_TYPE_HOMEPAGE = "homepage URL"

module_function

def github_repo_data(user, repo)
Expand Down