Merge pull request #4027 from SENG480-18/master
Simplify `search_taps` method and handle errors
This commit is contained in:
commit
c73e873893
@ -108,15 +108,22 @@ 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 = GitHub.search_code(user: ["Homebrew", "caskroom"], filename: query, extension: "rb")
|
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|
|
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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user