diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 2801cb9758b7b..8ae681d6acc3c 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -806,8 +806,13 @@ def audit_livecheck_version ) if result throttle = cask.livecheck.throttle - throttle ||= referenced_cask.livecheck.throttle if referenced_cask - latest_version = throttle ? result[:latest_throttled] : result[:latest] + throttle_days = cask.livecheck.throttle_days + if referenced_cask + throttle ||= referenced_cask.livecheck.throttle + throttle_days ||= referenced_cask.livecheck.throttle_days + end + + latest_version = (throttle || throttle_days) ? result[:latest_throttled] : result[:latest] end if latest_version && (cask.version.to_s == latest_version.to_s) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index ea58a42ce1099..77dca9dfd9ef0 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -1193,10 +1193,18 @@ def self.throttle_allows_bump?(formula_or_cask, version, throttle_rate: nil, thr end return if sourcefile.nil? + default_branch = Utils.popen_read( + Utils::Git.git, + "symbolic-ref", + "refs/remotes/origin/HEAD", + "--short", + ).chomp.delete_prefix("origin/").presence || "main" + relative_sourcefile = sourcefile.relative_path_from(tap.path).to_s timestamp = Utils.popen_read( Utils::Git.git, "log", + default_branch, "-1", "--format=%ct", "--", diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 7660138e7a306..d9584e3503e6a 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -637,6 +637,37 @@ def tmp_cask(name, text) end end + context "when the Cask has a `livecheck` block using `throttle days:`" do + let(:cask_token) { "livecheck-throttle-days" } + let(:cask) do + tmp_cask cask_token.to_s, <<~RUBY + cask "#{cask_token}" do + version "1.2.5" + sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" + + url "https://brew.sh/#{cask_token}-1.2.5.dmg" + name "Throttle Days" + homepage "https://brew.sh/#{cask_token}" + + livecheck do + url :homepage + throttle days: 7 + end + + app "#{cask_token}.app" + end + RUBY + end + + it do + allow(Homebrew::Livecheck).to receive(:latest_version).and_return({ + latest: Version.new("1.2.6"), + latest_throttled: Version.new("1.2.5"), + }) + expect(run).not_to error_with(message) + end + end + context "when the Cask has a `livecheck` block referencing a Cask that uses `throttle`" do let(:cask_token) { "livecheck-throttle-reference" } @@ -648,6 +679,58 @@ def tmp_cask(name, text) expect(run).not_to error_with(message) end end + + context "when the Cask has a `livecheck` block referencing a Cask that uses `throttle days:`" do + let(:cask_token) { "livecheck-throttle-days-reference" } + let(:referenced_cask) do + tmp_cask "livecheck-throttle-days-source", <<~RUBY + cask "livecheck-throttle-days-source" do + version "1.2.5" + sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" + + url "https://brew.sh/livecheck-throttle-days-source-1.2.5.dmg" + name "Throttle Days Source" + homepage "https://brew.sh/livecheck-throttle-days-source" + + livecheck do + url :homepage + throttle days: 7 + end + + app "livecheck-throttle-days-source.app" + end + RUBY + end + let(:cask) do + tmp_cask cask_token.to_s, <<~RUBY + cask "#{cask_token}" do + version "1.2.5" + sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b" + + url "https://brew.sh/#{cask_token}-1.2.5.dmg" + name "Throttle Days Reference" + homepage "https://brew.sh/#{cask_token}" + + livecheck do + cask "livecheck-throttle-days-source" + end + + app "#{cask_token}.app" + end + RUBY + end + + it do + allow(Homebrew::Livecheck).to receive_messages( + resolve_livecheck_reference: [referenced_cask, nil], + latest_version: { + latest: Version.new("1.2.6"), + latest_throttled: Version.new("1.2.5"), + }, + ) + expect(run).not_to error_with(message) + end + end end describe "when the Cask stanza requires uninstall" do