From 403b0bf3f16eef8c4ffacd52c935e738f741446d Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:29:36 -0400 Subject: [PATCH] contributions: resolve type errors This updates the type signature for `#scan_repositories` to address a runtime type error and to reflect the actual return type. The logic in `#scan_repositories` to check for unsupported repositories leads to a type error, as `#ofail` has a void return type. To resolve this, I moved the repository verification code into `#run` (after `repos` is defined but before it's used) and used `#odie`, so the command will exit early with an error. While I was at it, I updated the type for the `repos` parameter to not be `nilable`, as it shouldn't be `nil` based on how we're handling `repos` in `#run`. --- Library/Homebrew/dev-cmd/contributions.rb | 35 ++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/dev-cmd/contributions.rb b/Library/Homebrew/dev-cmd/contributions.rb index dbad695b9f..ef175a4fc4 100644 --- a/Library/Homebrew/dev-cmd/contributions.rb +++ b/Library/Homebrew/dev-cmd/contributions.rb @@ -48,12 +48,20 @@ module Homebrew results = {} grand_totals = {} - repos = if args.repositories.blank? || args.repositories&.include?("primary") - PRIMARY_REPOS - elsif args.repositories&.include?("all") - SUPPORTED_REPOS - else - args.repositories + repos = T.must( + if args.repositories.blank? || args.repositories&.include?("primary") + PRIMARY_REPOS + elsif args.repositories&.include?("all") + SUPPORTED_REPOS + else + args.repositories + end, + ) + + repos.each do |repo| + if SUPPORTED_REPOS.exclude?(repo) + odie "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}." + end end from = args.from.presence || Date.today.prev_year.iso8601 @@ -150,17 +158,18 @@ module Homebrew ] end - sig { params(repos: T.nilable(T::Array[String]), person: String, from: String).void } + sig { + params( + repos: T::Array[String], + person: String, + from: String, + ).returns(T::Hash[Symbol, T.untyped]) + } def scan_repositories(repos, person, from:) - return if repos.blank? - data = {} + return data if repos.blank? repos.each do |repo| - if SUPPORTED_REPOS.exclude?(repo) - return ofail "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}." - end - repo_path = find_repo_path_for_repo(repo) tap = Tap.fetch("homebrew", repo) unless repo_path.exist?