From 84abc628aa94c6d33029ccea6bc20c551726ca97 Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Wed, 24 Apr 2024 04:07:25 +0800 Subject: [PATCH] utils/github: paginate artifact API result There can be too many artifacts in a workflow run to fit in a single API response, so we need to paginate the result. --- Library/Homebrew/utils/github.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index d2cde79847..f7cf045793 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -355,10 +355,17 @@ module GitHub end run_id = check_suite.last["workflowRun"]["databaseId"] - artifacts = API.open_rest("#{API_URL}/repos/#{user}/#{repo}/actions/runs/#{run_id}/artifacts", scopes:) + artifacts = [] + per_page = 50 + API.paginate_rest("#{API_URL}/repos/#{user}/#{repo}/actions/runs/#{run_id}/artifacts", + per_page:, scopes:) do |result| + result = result["artifacts"] + artifacts.concat(result) + break if result.length < per_page + end matching_artifacts = - artifacts["artifacts"] + artifacts .group_by { |art| art["name"] } .select { |name| File.fnmatch?(artifact_pattern, name, File::FNM_EXTGLOB) } .map { |_, arts| arts.last }