Merge pull request #4027 from SENG480-18/master

Simplify `search_taps` method and handle errors
This commit is contained in:
Mike McQuaid 2018-04-08 23:17:51 +01:00 committed by GitHub
commit c73e873893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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