From 85684f43bd3cf2d0a7350224bab262b47f750f1f Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 3 May 2025 12:13:19 -0400 Subject: [PATCH] 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. --- Library/Homebrew/formula_auditor.rb | 7 +++---- Library/Homebrew/utils/shared_audits.rb | 13 +++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index d555e99d22..1b17af76c6 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -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? diff --git a/Library/Homebrew/utils/shared_audits.rb b/Library/Homebrew/utils/shared_audits.rb index 9ba8c9f9ac..2269e0ab1e 100644 --- a/Library/Homebrew/utils/shared_audits.rb +++ b/Library/Homebrew/utils/shared_audits.rb @@ -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