mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00

`brew bump` will check for PRs related to a package even if the package version and livecheck version are the same. We're presumably only interested in related PRs when the livecheck version differs, so we can reduce GitHub API requests by skipping the check(s) when the versions are equal. We use `bump` in `autobump` workflows, so this should help with recent rate limiting issues (e.g., 3203 out of 3426 autobumped formulae were up to date in a recent run). This also reworks the output for duplicate PRs, making it clear when `bump` skipped checking PRs (as printing "none" would suggest that PRs were checked) and only printing the "Maybe duplicate" information when checked. This makes it a little easier to understand what `bump` has done internally from the output.
60 lines
2.0 KiB
Ruby
60 lines
2.0 KiB
Ruby
# typed: strict
|
|
# frozen_string_literal: true
|
|
|
|
module Homebrew
|
|
# Class handling architecture-specific version information.
|
|
class BumpVersionParser
|
|
sig { returns(T.nilable(T.any(Version, Cask::DSL::Version))) }
|
|
attr_reader :arm, :general, :intel
|
|
|
|
sig {
|
|
params(general: T.nilable(T.any(Version, String)),
|
|
arm: T.nilable(T.any(Version, String)),
|
|
intel: T.nilable(T.any(Version, String))).void
|
|
}
|
|
def initialize(general: nil, arm: nil, intel: nil)
|
|
@general = T.let(parse_version(general), T.nilable(T.any(Version, Cask::DSL::Version))) if general.present?
|
|
@arm = T.let(parse_version(arm), T.nilable(T.any(Version, Cask::DSL::Version))) if arm.present?
|
|
@intel = T.let(parse_version(intel), T.nilable(T.any(Version, Cask::DSL::Version))) if intel.present?
|
|
|
|
return if @general.present?
|
|
raise UsageError, "`--version` must not be empty." if arm.blank? && intel.blank?
|
|
raise UsageError, "`--version-arm` must not be empty." if arm.blank?
|
|
raise UsageError, "`--version-intel` must not be empty." if intel.blank?
|
|
end
|
|
|
|
sig {
|
|
params(version: T.any(Version, String))
|
|
.returns(T.nilable(T.any(Version, Cask::DSL::Version)))
|
|
}
|
|
def parse_version(version)
|
|
if version.is_a?(Version)
|
|
version
|
|
elsif version.is_a?(String)
|
|
parse_cask_version(version)
|
|
end
|
|
end
|
|
|
|
sig { params(version: String).returns(T.nilable(Cask::DSL::Version)) }
|
|
def parse_cask_version(version)
|
|
if version == "latest"
|
|
Cask::DSL::Version.new(:latest)
|
|
else
|
|
Cask::DSL::Version.new(version)
|
|
end
|
|
end
|
|
|
|
sig { returns(T::Boolean) }
|
|
def blank?
|
|
@general.blank? && @arm.blank? && @intel.blank?
|
|
end
|
|
|
|
sig { params(other: T.untyped).returns(T::Boolean) }
|
|
def ==(other)
|
|
return false unless other.is_a?(BumpVersionParser)
|
|
|
|
(general == other.general) && (arm == other.arm) && (intel == other.intel)
|
|
end
|
|
end
|
|
end
|