From 414e221990061893c95fb5d4798169733c30a84c Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 26 Apr 2024 09:37:48 +0100 Subject: [PATCH] utils/analytics: cleanup test-bot analytics. Sort options to ensure consistent ordering and improve readability. Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> --- Library/Homebrew/utils/analytics.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index fe1770c0a9df5..56eba82fc1053 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -144,10 +144,23 @@ def report_test_bot_test(step_command_short, passed) os: HOMEBREW_SYSTEM, } + command_and_package, options = + step_command_short.split + .partition { |arg| !arg.start_with?("-") } + # Strip out any flag values to reduce cardinality and preserve privacy. - command = step_command_short.split - .map { |arg| arg.sub(/=.*/, "=") } - .join(" ") + # Sort options to ensure consistent ordering and improve readability. + options = options.join(" ") + .split + .join(" ") + .split(/(-+)/) + .map { |a| a.sub(/[ =].+/, " ") } + .join(" ") + .strip + .split + .sort + + command = (command_and_package + options).join(" ") # Fields can have high cardinality. fields = { command: }