From 963605e68209641c2b7dad817975ead5007934b4 Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Sat, 11 Jul 2020 11:28:37 -0400 Subject: [PATCH] refactor throttled update logic to improve efficiency --- Library/Homebrew/dev-cmd/audit.rb | 29 +++++++++------------ Library/Homebrew/test/dev-cmd/audit_spec.rb | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 81ae3b5026..b961acd9c4 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -571,13 +571,13 @@ module Homebrew imagemagick@6 ].freeze - THROTTLED_DENYLIST = { - "aws-sdk-cpp" => "10", - "awscli@1" => "10", - "balena-cli" => "10", - "gatsby-cli" => "10", - "quicktype" => "10", - "vim" => "50", + THROTTLED_FORMULAE = { + "aws-sdk-cpp" => 10, + "awscli@1" => 10, + "balena-cli" => 10, + "gatsby-cli" => 10, + "quicktype" => 10, + "vim" => 50, }.freeze UNSTABLE_ALLOWLIST = { @@ -667,15 +667,6 @@ module Homebrew problem head_spec_message unless VERSIONED_HEAD_SPEC_ALLOWLIST.include?(formula.name) end - THROTTLED_DENYLIST.each do |f, v| - next if formula.stable.nil? - - version = formula.stable.version.to_s.split(".").last.to_i - if f == formula.name && version.modulo(v.to_i).nonzero? - problem "should only be updated every #{v} releases on multiples of #{v}" - end - end - stable = formula.stable return unless stable return unless stable.url @@ -686,6 +677,12 @@ module Homebrew .split(".", 3) .map(&:to_i) + formula_suffix = stable_version_string.split(".").last.to_i + throttled_rate = THROTTLED_FORMULAE[formula.name] + if throttled_rate && formula_suffix.modulo(throttled_rate).nonzero? + problem "should only be updated every #{throttled_rate} releases on multiples of #{throttled_rate}" + end + case (url = stable.url) when /[\d._-](alpha|beta|rc\d)/ matched = Regexp.last_match(1) diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index 75a5fa8af8..9b80945ebf 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -542,7 +542,7 @@ module Homebrew include_examples "formulae exist", described_class::VERSIONED_KEG_ONLY_ALLOWLIST include_examples "formulae exist", described_class::VERSIONED_HEAD_SPEC_ALLOWLIST include_examples "formulae exist", described_class::USES_FROM_MACOS_ALLOWLIST - include_examples "formulae exist", described_class::THROTTLED_DENYLIST.keys + include_examples "formulae exist", described_class::THROTTLED_FORMULAE.keys include_examples "formulae exist", described_class::UNSTABLE_ALLOWLIST.keys include_examples "formulae exist", described_class::GNOME_DEVEL_ALLOWLIST.keys end