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.to_s)
|
||||||
metadata ||= SharedAudits.eol_data(name, formula.version.major_minor.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
|
eol_from = metadata.dig("result", "eolFrom")
|
||||||
is_eol ||= eol.is_a?(String) && (eol_date = Date.parse(eol)) <= Date.today
|
eol_date = Date.parse(eol_from) if eol_from.present?
|
||||||
return unless is_eol
|
|
||||||
|
|
||||||
message = "Product is EOL"
|
message = "Product is EOL"
|
||||||
message += " since #{eol_date}" if eol_date.present?
|
message += " since #{eol_date}" if eol_date.present?
|
||||||
|
|||||||
@ -12,10 +12,15 @@ module SharedAudits
|
|||||||
def self.eol_data(product, cycle)
|
def self.eol_data(product, cycle)
|
||||||
@eol_data ||= T.let({}, T.nilable(T::Hash[String, T.untyped]))
|
@eol_data ||= T.let({}, T.nilable(T::Hash[String, T.untyped]))
|
||||||
@eol_data["#{product}/#{cycle}"] ||= begin
|
@eol_data["#{product}/#{cycle}"] ||= begin
|
||||||
result = Utils::Curl.curl_output("--location", "https://endoflife.date/api/#{product}/#{cycle}.json")
|
result = Utils::Curl.curl_output("--location", "https://endoflife.date/api/v1/products/#{product}/releases/#{cycle}")
|
||||||
json = JSON.parse(result.stdout) if result.status.success?
|
|
||||||
json = nil if json&.dig("message")&.include?("Product not found")
|
if result.status.success?
|
||||||
json
|
begin
|
||||||
|
JSON.parse(result.stdout)
|
||||||
|
rescue JSON::ParserError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user