aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils.rb
diff options
context:
space:
mode:
authorDaniel Lee Harple2013-05-14 10:42:46 -0400
committerJack Nagel2013-05-22 19:53:04 -0500
commita113ebbfee5cfc96f95f1ac13b2ea110e58e05cc (patch)
tree8d85bbf3ac42f6a033e46c302df01228d190df99 /Library/Homebrew/utils.rb
parent46941be352958eccec42d04894534b1c05f357a3 (diff)
downloadhomebrew-a113ebbfee5cfc96f95f1ac13b2ea110e58e05cc.tar.bz2
Check GitHub API rate limit instead of silently failing
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Homebrew/utils.rb')
-rw-r--r--Library/Homebrew/utils.rb31
1 files changed, 21 insertions, 10 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 7506c87a4..ad943b6f8 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -259,7 +259,16 @@ end
module GitHub extend self
def open url, headers={}, &block
require 'open-uri'
- Kernel.open(url, headers.merge('User-Agent' => HOMEBREW_USER_AGENT), &block)
+ begin
+ Kernel.open(url, {'User-Agent' => HOMEBREW_USER_AGENT}.merge(headers), &block)
+ rescue OpenURI::HTTPError => e
+ if e.io.meta['x-ratelimit-remaining'].to_i <= 0
+ require 'vendor/multi_json'
+ raise "GitHub #{MultiJson.decode(e.io.read)['message']}"
+ else
+ raise e
+ end
+ end
end
def issues_for_formula name
@@ -276,15 +285,16 @@ module GitHub extend self
uri = URI.parse("https://api.github.com/legacy/issues/search/mxcl/homebrew/open/#{name}")
open uri do |f|
- MultiJson.decode(f.read)['issues'].each do |issue|
- # don't include issues that just refer to the tool in their body
- issues << issue['html_url'] if issue['title'].include? name
+ begin
+ MultiJson.decode(f.read)['issues'].each do |issue|
+ # don't include issues that just refer to the tool in their body
+ issues << issue['html_url'] if issue['title'].include? name
+ end
+ rescue
end
end
issues
- rescue
- []
end
def find_pull_requests rx
@@ -294,11 +304,12 @@ module GitHub extend self
uri = URI.parse("https://api.github.com/legacy/issues/search/mxcl/homebrew/open/#{query}")
GitHub.open uri do |f|
- MultiJson.decode(f.read)['issues'].each do |pull|
- yield pull['pull_request_url'] if rx.match pull['title'] and pull['pull_request_url']
+ begin
+ MultiJson.decode(f.read)['issues'].each do |pull|
+ yield pull['pull_request_url'] if rx.match pull['title'] and pull['pull_request_url']
+ end
+ rescue
end
end
- rescue
- nil
end
end