From 709afd58ed9f6adb953098de756dd4b0df8a7467 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Sat, 16 Mar 2024 22:42:52 -0400 Subject: [PATCH] dev-cmd/bump-formula-pr: replace partial version in URL For now, restrict to partial version excluding the last part, i.e. version with major.minor.patch will result in attempting to replace any occurrences of "/#{major}.#{minor}/" or "/v#{major}.#{minor}/". This should take care of common situations like GNOME, KDE, and SourceForge URLs. It should also help with URLs like `util-linux`. It may result in incorrect replacements if URL has partial version based on another versioning scheme like the API version or if there are some equivalent numbers in URL that happen to match Signed-off-by: Michael Cho --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 3402a62a6f..4ed5dbb345 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -192,10 +192,10 @@ module Homebrew else new_url ||= PyPI.update_pypi_url(old_url, new_version) if new_url.blank? - new_url = old_url.gsub(old_version, new_version) + new_url = update_url(old_url, old_version, new_version) if new_mirrors.blank? && old_mirrors.present? new_mirrors = old_mirrors.map do |old_mirror| - old_mirror.gsub(old_version, new_version) + update_url(old_mirror, old_version, new_version) end end end @@ -419,6 +419,17 @@ module Homebrew end end + sig { params(old_url: String, old_version: String, new_version: String).returns(String) } + def update_url(old_url, old_version, new_version) + new_url = old_url.gsub(old_version, new_version) + return new_url if (old_version_parts = old_version.split(".")).length < 2 + return new_url if (new_version_parts = new_version.split(".")).length != old_version_parts.length + + partial_old_version = T.must(old_version_parts[0..-2]).join(".") + partial_new_version = T.must(new_version_parts[0..-2]).join(".") + new_url.gsub(%r{/(v?)#{Regexp.escape(partial_old_version)}/}, "/\\1#{partial_new_version}/") + end + def fetch_resource_and_forced_version(formula, new_version, url, **specs) resource = Resource.new resource.url(url, **specs)