aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2014-02-16 22:24:33 -0500
committerJack Nagel2014-02-16 23:11:17 -0500
commit24cbb4fd2ec81a05991f759c647478f7a8aedcf8 (patch)
tree85924fe384b2fe385b9a6f8cbf3a83703fb12a99
parentf7cda3cdb6656a867a2d760d70a199892fde8ce2 (diff)
downloadbrew-24cbb4fd2ec81a05991f759c647478f7a8aedcf8.tar.bz2
Add a more useful message when ratelimit is exceeded
-rw-r--r--Library/Homebrew/utils.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index efc4d93a6..1f305a3b8 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -280,10 +280,13 @@ module GitHub extend self
end
def handle_api_error(e)
- if e.io.meta['x-ratelimit-remaining'].to_i <= 0
+ if e.io.meta["x-ratelimit-remaining"].to_i <= 0
+ reset = e.io.meta.fetch("x-ratelimit-reset").to_i
+
raise RateLimitExceededError, <<-EOS.undent, e.backtrace
GitHub #{Utils::JSON.load(e.io.read)['message']}
- You may want to create an API token: https://github.com/settings/applications
+ Try again in #{pretty_ratelimit_reset(reset)}, or create an API token:
+ https://github.com/settings/applications
and then set HOMEBREW_GITHUB_API_TOKEN.
EOS
end
@@ -298,6 +301,14 @@ module GitHub extend self
end
end
+ def pretty_ratelimit_reset(reset)
+ if (seconds = Time.at(reset) - Time.now) > 180
+ "%d minutes %d seconds" % [seconds / 60, seconds % 60]
+ else
+ "#{seconds} seconds"
+ end
+ end
+
def issues_matching(query, qualifiers={})
uri = ISSUES_URI.dup
uri.query = build_query_string(query, qualifiers)