search: return matches from open pull requests
When search can't find any local results, hit the GitHub API and search the titles of pending pull requests. This will help people find the many proposed formulae and prevent them from wasting time duplicating them. Closes Homebrew/homebrew#9018. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
d106cfed06
commit
79439626b5
@ -9,7 +9,13 @@ module Homebrew extend self
|
||||
exec "open", "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}"
|
||||
else
|
||||
query = ARGV.first
|
||||
search_results = search_brews query
|
||||
rx = if query =~ %r{^/(.*)/$}
|
||||
Regexp.new($1)
|
||||
else
|
||||
/.*#{Regexp.escape query}.*/i
|
||||
end
|
||||
|
||||
search_results = search_brews rx
|
||||
puts_columns search_results
|
||||
|
||||
if not query.to_s.empty? and $stdout.tty? and msg = blacklisted?(query)
|
||||
@ -20,19 +26,20 @@ module Homebrew extend self
|
||||
end
|
||||
puts msg
|
||||
end
|
||||
|
||||
if search_results.empty? and not blacklisted? query
|
||||
pulls = GitHub.find_pull_requests rx
|
||||
unless pulls.empty?
|
||||
puts "Open pull requests matching \"#{query}\":", *pulls.map { |p| " #{p}" }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def search_brews text
|
||||
if text.to_s.empty?
|
||||
def search_brews rx
|
||||
if rx.to_s.empty?
|
||||
Formula.names
|
||||
else
|
||||
rx = if text =~ %r{^/(.*)/$}
|
||||
Regexp.new($1)
|
||||
else
|
||||
/.*#{Regexp.escape text}.*/i
|
||||
end
|
||||
|
||||
aliases = Formula.aliases
|
||||
results = (Formula.names+aliases).grep rx
|
||||
|
||||
@ -45,5 +52,4 @@ module Homebrew extend self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -427,4 +427,28 @@ module GitHub extend self
|
||||
rescue
|
||||
[]
|
||||
end
|
||||
|
||||
def find_pull_requests rx
|
||||
require 'open-uri'
|
||||
require 'vendor/multi_json'
|
||||
|
||||
pulls = []
|
||||
uri = URI.parse("https://api.github.com/repos/mxcl/homebrew/pulls")
|
||||
uri.query = "per_page=100"
|
||||
|
||||
open uri do |f|
|
||||
MultiJson.decode((f.read)).each do |pull|
|
||||
pulls << pull['html_url'] if rx.match pull['title']
|
||||
end
|
||||
|
||||
uri = if f.meta['link'] =~ /rel="next"/
|
||||
f.meta['link'].slice(URI.regexp)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end while uri
|
||||
pulls
|
||||
rescue
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user