[DRE-commits] [librarian-puppet] 15/97: help users overcome rate limits

Stig Sandbeck Mathisen ssm at debian.org
Tue Mar 11 12:12:47 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository librarian-puppet.

commit 49c0b3d53e04ce257dab5512c36f8ae4302e3d4a
Author: grosser <michael at grosser.it>
Date:   Fri Nov 22 11:36:11 2013 -0800

    help users overcome rate limits
---
 Rakefile                                           | 2 +-
 lib/librarian/puppet/source/githubtarball.rb       | 5 +++--
 test/librarian/puppet/source/githubtarball_test.rb | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/Rakefile b/Rakefile
index 0e66e69..eccd8e1 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,4 @@
-require 'bundlet/setup'
+require 'bundler/setup'
 require 'cucumber/rake/task'
 require 'bundler/gem_tasks'
 require 'rake/testtask'
diff --git a/lib/librarian/puppet/source/githubtarball.rb b/lib/librarian/puppet/source/githubtarball.rb
index 7f94c25..d45cf32 100644
--- a/lib/librarian/puppet/source/githubtarball.rb
+++ b/lib/librarian/puppet/source/githubtarball.rb
@@ -9,6 +9,7 @@ module Librarian
     module Source
       class GitHubTarball
         class Repo
+          TOKEN_KEY = 'GITHUB_API_TOKEN'
 
           attr_accessor :source, :name
           private :source=, :name=
@@ -114,7 +115,7 @@ module Librarian
 
           def api_call(path)
             url = "https://api.github.com#{path}"
-            url << "?access_token=#{ENV['GITHUB_API_TOKEN']}" if ENV['GITHUB_API_TOKEN']
+            url << "?access_token=#{ENV[TOKEN_KEY]}" if ENV[TOKEN_KEY]
             code, data = http_get(url, :headers => {
               "User-Agent" => "librarian-puppet v#{Librarian::Puppet::VERSION}"
             })
@@ -125,7 +126,7 @@ module Librarian
               begin
                 message = JSON.parse(data)['message']
                 if message && message.include?('API rate limit exceeded')
-                  raise Error, message
+                  raise Error, message + " -- increase limit by authenticating via #{TOKEN_KEY}=your-token"
                 end
               rescue JSON::ParserError
                 # 403 response does not return json, skip.
diff --git a/test/librarian/puppet/source/githubtarball_test.rb b/test/librarian/puppet/source/githubtarball_test.rb
index e43f35b..05dbc23 100644
--- a/test/librarian/puppet/source/githubtarball_test.rb
+++ b/test/librarian/puppet/source/githubtarball_test.rb
@@ -24,7 +24,8 @@ describe Librarian::Puppet::Source::GitHubTarball::Repo do
     it "fails when we hit api limit" do
       response = {"message" => "Oh boy! API rate limit exceeded!!!"}
       repo.expects(:http_get).with('https://api.github.com/foo', {:headers => headers}).returns([403, JSON.dump(response)])
-      assert_exact_error Librarian::Error, "Oh boy! API rate limit exceeded!!!" do
+      message = "Oh boy! API rate limit exceeded!!! -- increase limit by authenticating via GITHUB_API_TOKEN=your-token"
+      assert_exact_error Librarian::Error, message do
         repo.send(:api_call, "/foo")
       end
     end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/librarian-puppet.git



More information about the Pkg-ruby-extras-commits mailing list