aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2014-02-08 16:04:53 -0500
committerJack Nagel2014-02-08 16:04:53 -0500
commit4d6df3e3bca5147f49deb530d930b2f40b032cd1 (patch)
tree0b1edffaace3d05231edca4b493b73083b461046 /Library
parentf7e1244e6d761aff3c1e0228e560efb6f73f8e75 (diff)
downloadbrew-4d6df3e3bca5147f49deb530d930b2f40b032cd1.tar.bz2
Parse JSON early in GitHub module
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/search.rb11
-rw-r--r--Library/Homebrew/utils.rb8
2 files changed, 10 insertions, 9 deletions
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index 476b24b49..a03738bc8 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -1,7 +1,6 @@
require 'formula'
require 'blacklist'
require 'utils'
-require 'utils/json'
module Homebrew extend self
@@ -103,9 +102,9 @@ module Homebrew extend self
return [] if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}-#{repo.downcase}").directory?
results = []
- GitHub.open "https://api.github.com/repos/#{user}/homebrew-#{repo}/git/trees/HEAD?recursive=1" do |f|
+ GitHub.open "https://api.github.com/repos/#{user}/homebrew-#{repo}/git/trees/HEAD?recursive=1" do |json|
user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization
- Utils::JSON.load(f.read)["tree"].map{ |hash| hash['path'] }.compact.each do |file|
+ json["tree"].map{ |hash| hash['path'] }.compact.each do |file|
name = File.basename(file, '.rb')
if file =~ /\.rb$/ and name =~ rx
results << "#{user}/#{repo}/#{name}"
@@ -113,10 +112,8 @@ module Homebrew extend self
end
end
results
- rescue OpenURI::HTTPError, GitHub::Error, Utils::JSON::Error
- opoo <<-EOS.undent
- Failed to search tap: #{user}/#{repo}. Please run `brew update`.
- EOS
+ rescue OpenURI::HTTPError, GitHub::Error
+ opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
[]
end
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index f48e92b83..2f5bf1b0d 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -261,7 +261,9 @@ module GitHub extend self
default_headers = {'User-Agent' => HOMEBREW_USER_AGENT}
default_headers['Authorization'] = "token #{HOMEBREW_GITHUB_API_TOKEN}" if HOMEBREW_GITHUB_API_TOKEN
- Kernel.open(url, default_headers.merge(headers), &block)
+ Kernel.open(url, default_headers.merge(headers)) do |f|
+ yield Utils::JSON.load(f.read)
+ end
rescue OpenURI::HTTPError => e
if e.io.meta['x-ratelimit-remaining'].to_i <= 0
raise <<-EOS.undent
@@ -274,11 +276,13 @@ module GitHub extend self
end
rescue SocketError, OpenSSL::SSL::SSLError => e
raise Error, "Failed to connect to: #{url}\n#{e.message}"
+ rescue Utils::JSON::Error => e
+ raise Error, "Failed to parse JSON response\n#{e.message}"
end
def issues_matching(query)
uri = ISSUES_URI + uri_escape(query)
- open(uri) { |f| Utils::JSON.load(f.read)['issues'] }
+ open(uri) { |json| json["issues"] }
end
def uri_escape(query)