Skip to content

Commit

Permalink
Get rid of even more T.musts
Browse files Browse the repository at this point in the history
Co-authored-by: Mike McQuaid <[email protected]>
  • Loading branch information
issyl0 and MikeMcQuaid committed Jul 3, 2024
1 parent 3d09094 commit 84e4ece
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Library/Homebrew/dev-cmd/bump-formula-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ def run

old_mirrors = formula_spec.mirrors
new_mirrors ||= args.mirror
new_mirror ||= determine_mirror(T.must(new_url))
new_mirror ||= determine_mirror(new_url)
new_mirrors ||= [new_mirror] if new_mirror.present?

check_for_mirrors(formula, old_mirrors, T.must(new_mirrors)) if new_url.present?
check_for_mirrors(formula, old_mirrors, new_mirrors) if new_url.present?

old_hash = formula_spec.checksum&.hexdigest
new_hash = args.sha256
Expand Down Expand Up @@ -179,7 +178,7 @@ def run
EOS
end
check_new_version(formula, tap_remote_repo, url: old_url, tag: new_tag) if new_version.blank?
resource_path, forced_version = fetch_resource_and_forced_version(formula, T.must(new_version), old_url,
resource_path, forced_version = fetch_resource_and_forced_version(formula, new_version, old_url,
tag: new_tag)
new_revision = Utils.popen_read("git", "-C", resource_path.to_s, "rev-parse", "-q", "--verify", "HEAD")
new_revision = new_revision.strip
Expand All @@ -190,12 +189,12 @@ def run
elsif new_url.blank? && new_version.blank?
raise UsageError, "#{formula}: no `--url` or `--version` argument specified!"
else
new_url ||= PyPI.update_pypi_url(old_url, T.must(new_version))
new_url ||= PyPI.update_pypi_url(old_url, new_version)
if new_url.blank?
new_url = update_url(old_url, old_version, T.must(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|
update_url(old_mirror, old_version, T.must(new_version))
update_url(old_mirror, old_version, new_version)
end
end
end
Expand All @@ -207,7 +206,7 @@ def run
EOS
end
check_new_version(formula, tap_remote_repo, url: new_url) if new_version.blank?
resource_path, forced_version = fetch_resource_and_forced_version(formula, T.must(new_version), new_url)
resource_path, forced_version = fetch_resource_and_forced_version(formula, new_version, new_url)
Utils::Tar.validate_file(resource_path)
new_hash = resource_path.sha256
end
Expand Down Expand Up @@ -273,7 +272,7 @@ def run

if new_mirrors.present?
replacement_pairs << [
/^( +)(url "#{Regexp.escape(T.must(new_url))}"[^\n]*?\n)/m,
/^( +)(url "#{Regexp.escape(new_url)}"[^\n]*?\n)/m,
"\\1\\2\\1mirror \"#{new_mirrors.join("\"\n\\1mirror \"")}\"\n",
]
end
Expand Down Expand Up @@ -395,8 +394,10 @@ def run

private

sig { params(url: String).returns(T.nilable(String)) }
sig { params(url: T.nilable(String)).returns(T.nilable(String)) }
def determine_mirror(url)
return if url.blank?

case url
when %r{.*ftp\.gnu\.org/gnu.*}
url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org"
Expand Down Expand Up @@ -483,7 +484,9 @@ def check_new_version(formula, tap_remote_repo, version: nil, url: nil, tag: nil
if version.nil?
specs = {}
specs[:tag] = tag if tag.present?
version = Version.detect(T.must(url), **specs).to_s
return if url.blank?

version = Version.detect(url, **specs).to_s
return if version.blank?
end

Expand Down Expand Up @@ -558,7 +561,9 @@ def run_audit(formula, alias_rename, old_contents)
end
return
end
FileUtils.mv T.must(alias_rename.first), T.must(alias_rename.last) if alias_rename.present?
if alias_rename && (source = alias_rename.first) && (destination = alias_rename.last)
FileUtils.mv source, destination
end
failed_audit = false
if args.no_audit?
ohai "Skipping `brew audit`"
Expand All @@ -572,7 +577,9 @@ def run_audit(formula, alias_rename, old_contents)
return unless failed_audit

formula.path.atomic_write(old_contents)
FileUtils.mv T.must(alias_rename.last), T.must(alias_rename.first) if alias_rename.present?
if alias_rename && (source = alias_rename.first) && (destination = alias_rename.last)
FileUtils.mv source, destination
end
odie "`brew audit` failed!"
end
end
Expand Down

0 comments on commit 84e4ece

Please sign in to comment.