Module: Repology Private
- Defined in:
- Library/Homebrew/utils/repology.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Repology API client.
Class Method Summary collapse
- .format_package(package_name, latest_version) ⇒ Object private
- .formula_data(package_name) ⇒ Object private
- .parse_api_response(limit = nil) ⇒ Object private
- .query_api(last_package_in_response = "") ⇒ Object private
- .single_package_query(name) ⇒ Object private
- .validate_and_format_packages(outdated_repology_packages, limit) ⇒ Object private
Class Method Details
.format_package(package_name, latest_version) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'Library/Homebrew/utils/repology.rb', line 90 def format_package(package_name, latest_version) formula = formula_data(package_name) return if formula.blank? formula_name = formula.to_s tap_full_name = formula.tap&.full_name current_version = formula.version.to_s livecheck_response = LivecheckFormula.init(package_name) pull_requests = GitHub.fetch_pull_requests(formula_name, tap_full_name, state: "open") if pull_requests.try(:any?) pull_requests = pull_requests.map { |pr| "#{pr["title"]} (#{Formatter.url(pr["html_url"])})" }.join(", ") end pull_requests = "none" if pull_requests.blank? { repology_latest_version: latest_version || "not found", current_formula_version: current_version.to_s, livecheck_latest_version: livecheck_response[:livecheck_version] || "not found", open_pull_requests: pull_requests, } end |
.formula_data(package_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
115 116 117 118 119 |
# File 'Library/Homebrew/utils/repology.rb', line 115 def formula_data(package_name) Formula[package_name] rescue nil end |
.parse_api_response(limit = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'Library/Homebrew/utils/repology.rb', line 36 def parse_api_response(limit = nil) ohai "Querying outdated packages from Repology" page_no = 1 outdated_packages = {} last_package_index = "" while page_no <= MAX_PAGINATION odebug "Paginating Repology API page: #{page_no}" response = query_api(last_package_index.to_s) response_size = response.size outdated_packages.merge!(response) last_package_index = outdated_packages.size - 1 page_no += 1 break if limit && outdated_packages.size >= limit || response_size <= 1 end puts "#{outdated_packages.size} outdated #{"package".pluralize(outdated_packages.size)} found" puts outdated_packages end |
.query_api(last_package_in_response = "") ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 18 19 20 21 |
# File 'Library/Homebrew/utils/repology.rb', line 15 def query_api(last_package_in_response = "") last_package_in_response += "/" if last_package_in_response.present? url = "https://repology.org/api/v1/projects/#{last_package_in_response}?inrepo=homebrew&outdated=1" output, _errors, _status = curl_output(url.to_s) JSON.parse(output) end |
.single_package_query(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'Library/Homebrew/utils/repology.rb', line 23 def single_package_query(name) url = "https://repology.org/api/v1/project/#{name}" output, _errors, _status = curl_output(url.to_s) data = JSON.parse(output) homebrew = data.select do |repo| repo["repo"] == "homebrew" end homebrew.empty? ? nil : { name => data } end |
.validate_and_format_packages(outdated_repology_packages, limit) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'Library/Homebrew/utils/repology.rb', line 61 def validate_and_format_packages(outdated_repology_packages, limit) if outdated_repology_packages.size > 10 && (limit.blank? || limit > 10) ohai "Verifying outdated repology packages" end packages = {} outdated_repology_packages.each do |_name, repositories| repology_homebrew_repo = repositories.find do |repo| repo["repo"] == "homebrew" end next if repology_homebrew_repo.blank? latest_version = repositories.find { |repo| repo["status"] == "newest" } next if latest_version.blank? latest_version = latest_version["version"] srcname = repology_homebrew_repo["srcname"] package_details = format_package(srcname, latest_version) packages[srcname] = package_details unless package_details.nil? break if limit && packages.size >= limit end packages end |