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 <michael@michaelcho.dev>
This commit is contained in:
parent
bb753a6c48
commit
709afd58ed
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user