diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 25c602b124..c61f4576a1 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -108,15 +108,22 @@ module Homebrew $stderr.puts Formatter.headline("Searching taps on GitHub...", color: :blue) end - valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze - matches = GitHub.search_code(user: ["Homebrew", "caskroom"], filename: query, extension: "rb") - + matches = begin + GitHub.search_code( + user: ["Homebrew", "caskroom"], + path: ["Formula", "HomebrewFormula", "Casks", "."], + filename: query, + extension: "rb", + ) + rescue GitHub::Error => error + opoo "Error searching on GitHub: #{error}\n" + [] + end matches.map do |match| - dirname, filename = File.split(match["path"]) - next unless valid_dirnames.include?(dirname) + filename = File.basename(match["path"], ".rb") tap = Tap.fetch(match["repository"]["full_name"]) next if tap.installed? && match["repository"]["owner"]["login"] != "caskroom" - "#{tap.name}/#{File.basename(filename, ".rb")}" + "#{tap.name}/#{filename}" end.compact end