Update eol_data for API changes
The endoflife.date API has been updated, so this modifies the URL in `SharedAudits.eol_data` to use the up to date URL and modifies the related logic in `FormulaAuditor.audit_eol` to work with the new response format. Specifically, there is now an `isEol` boolean value and the EOL date is found in `eolFrom`. One wrinkle of the new setup is that 404 responses now return HTML content even if the request includes an `Accept: application/json` header. This handles these types of responses by catching `JSON::ParserError` but ideally we would parse the response headers and use `Utils::Curl.http_status_ok?` to check for a good response status before trying to parse the response body as JSON.
This commit is contained in:
parent
97f9837a13
commit
85684f43bd
@ -612,11 +612,10 @@ module Homebrew
|
||||
metadata = SharedAudits.eol_data(name, formula.version.major.to_s)
|
||||
metadata ||= SharedAudits.eol_data(name, formula.version.major_minor.to_s)
|
||||
|
||||
return if metadata.blank? || (eol = metadata["eol"]).blank?
|
||||
return if metadata.blank? || (metadata.dig("result", "isEol") != true)
|
||||
|
||||
is_eol = eol == true
|
||||
is_eol ||= eol.is_a?(String) && (eol_date = Date.parse(eol)) <= Date.today
|
||||
return unless is_eol
|
||||
eol_from = metadata.dig("result", "eolFrom")
|
||||
eol_date = Date.parse(eol_from) if eol_from.present?
|
||||
|
||||
message = "Product is EOL"
|
||||
message += " since #{eol_date}" if eol_date.present?
|
||||
|
||||
@ -12,10 +12,15 @@ module SharedAudits
|
||||
def self.eol_data(product, cycle)
|
||||
@eol_data ||= T.let({}, T.nilable(T::Hash[String, T.untyped]))
|
||||
@eol_data["#{product}/#{cycle}"] ||= begin
|
||||
result = Utils::Curl.curl_output("--location", "https://endoflife.date/api/#{product}/#{cycle}.json")
|
||||
json = JSON.parse(result.stdout) if result.status.success?
|
||||
json = nil if json&.dig("message")&.include?("Product not found")
|
||||
json
|
||||
result = Utils::Curl.curl_output("--location", "https://endoflife.date/api/v1/products/#{product}/releases/#{cycle}")
|
||||
|
||||
if result.status.success?
|
||||
begin
|
||||
JSON.parse(result.stdout)
|
||||
rescue JSON::ParserError
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user