From 9ad60fe437c0d524836147086c528cc86affc51f Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Wed, 17 Apr 2024 07:35:40 +0800 Subject: [PATCH] utils/github: avoid returning artifacts with the same name --- Library/Homebrew/utils/github.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index a090cf87b3..d2cde79847 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -357,9 +357,11 @@ module GitHub run_id = check_suite.last["workflowRun"]["databaseId"] artifacts = API.open_rest("#{API_URL}/repos/#{user}/#{repo}/actions/runs/#{run_id}/artifacts", scopes:) - matching_artifacts = artifacts["artifacts"].select do |art| - File.fnmatch?(artifact_pattern, art["name"], File::FNM_EXTGLOB) - end + matching_artifacts = + artifacts["artifacts"] + .group_by { |art| art["name"] } + .select { |name| File.fnmatch?(artifact_pattern, name, File::FNM_EXTGLOB) } + .map { |_, arts| arts.last } if matching_artifacts.empty? raise API::Error, <<~EOS