More granular 'brew search' query == simpler code

This commit is contained in:
Stevie Howard 2018-04-06 23:14:30 -07:00
parent 296d48ba7a
commit d74721acc7
No known key found for this signature in database
GPG Key ID: 6E6BF71140B8DA95

View File

@ -110,10 +110,10 @@ module Homebrew
$stderr.puts Formatter.headline("Searching taps on GitHub...", color: :blue) $stderr.puts Formatter.headline("Searching taps on GitHub...", color: :blue)
end end
valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze
matches = begin matches = begin
GitHub.search_code( GitHub.search_code(
user: ["Homebrew", "caskroom"], user: ["Homebrew", "caskroom"],
path: ["Formula", "HomebrewFormula", "Casks", "."],
filename: query, filename: query,
extension: "rb", extension: "rb",
) )
@ -122,11 +122,10 @@ module Homebrew
[] []
end end
matches.map do |match| matches.map do |match|
dirname, filename = File.split(match["path"]) filename = File.basename(match["path"], ".rb")
next unless valid_dirnames.include?(dirname)
tap = Tap.fetch(match["repository"]["full_name"]) tap = Tap.fetch(match["repository"]["full_name"])
next if tap.installed? && match["repository"]["owner"]["login"] != "caskroom" next if tap.installed? && match["repository"]["owner"]["login"] != "caskroom"
"#{tap.name}/#{File.basename(filename, ".rb")}" "#{tap.name}/#{filename}"
end.compact end.compact
end end