do not paginate repology API more than required by limit
This commit is contained in:
parent
5d9e1f2bc7
commit
9904c862a1
@ -8,7 +8,7 @@ describe "brew bump" do
|
||||
end
|
||||
|
||||
describe "formula", :integration_test do
|
||||
it "returns data for valid specified formula" do
|
||||
it "returns data for single valid specified formula" do
|
||||
install_test_formula "testball"
|
||||
|
||||
expect { brew "bump", "testball" }
|
||||
@ -16,5 +16,15 @@ describe "brew bump" do
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
||||
it "returns data for multiple valid specified formula" do
|
||||
install_test_formula "testball"
|
||||
install_test_formula "testball2"
|
||||
|
||||
expect { brew "bump", "testball", "testball2" }
|
||||
.to output.to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -9,18 +9,6 @@ describe Repology do
|
||||
end
|
||||
end
|
||||
|
||||
describe "query_api" do
|
||||
it "returns a hash of data" do
|
||||
response = described_class.query_api
|
||||
|
||||
expect(response).not_to be_nil
|
||||
expect(response).to be_a(Hash)
|
||||
expect(response.size).not_to eq(0)
|
||||
# first hash in array val should include "repo" key/val pair
|
||||
expect(response[response.keys[0]].first).to include("repo")
|
||||
end
|
||||
end
|
||||
|
||||
describe "single_package_query" do
|
||||
it "returns nil for non-existent package" do
|
||||
response = described_class.single_package_query("invalidName")
|
||||
@ -37,7 +25,8 @@ describe Repology do
|
||||
end
|
||||
|
||||
describe "parse_api_response" do
|
||||
response = described_class.parse_api_response
|
||||
limit = 1
|
||||
response = described_class.parse_api_response(limit)
|
||||
|
||||
it "returns a hash of data" do
|
||||
expect(response).not_to be_nil
|
||||
|
||||
@ -5,6 +5,8 @@ require "utils/curl"
|
||||
module Repology
|
||||
module_function
|
||||
|
||||
MAX_PAGINATION = 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"
|
||||
@ -33,9 +35,8 @@ module Repology
|
||||
outdated_packages = query_api
|
||||
response_size = outdated_packages.size
|
||||
last_package_index = outdated_packages.size - 1
|
||||
max_pagination = limit.nil? ? 15 : (limit.to_f / 200).ceil
|
||||
|
||||
while response_size > 1 && page_no <= max_pagination
|
||||
while response_size > 1 && page_no <= MAX_PAGINATION
|
||||
odebug "Paginating Repology API page: #{page_no}"
|
||||
last_package_in_response = outdated_packages.keys[last_package_index]
|
||||
response = query_api(last_package_in_response)
|
||||
@ -43,10 +44,10 @@ module Repology
|
||||
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
|
||||
end
|
||||
|
||||
outdated_packages = outdated_packages.first(limit) if !limit.nil? && outdated_packages.size > limit
|
||||
|
||||
puts "#{outdated_packages.size} outdated #{"package".pluralize(outdated_packages.size)} found"
|
||||
puts
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user