[DRE-commits] [librarian-puppet] 23/97: Cache forge responses and print an error if returns an invalid response

Stig Sandbeck Mathisen ssm at debian.org
Tue Mar 11 12:12:48 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 7b5f669bf31df64951f01dd4ffb46f678970b635
Author: Carlos Sanchez <csanchez at maestrodev.com>
Date:   Thu Apr 18 23:37:11 2013 +0200

    Cache forge responses and print an error if returns an invalid response
---
 lib/librarian/puppet/source/forge.rb | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/librarian/puppet/source/forge.rb b/lib/librarian/puppet/source/forge.rb
index eb63b86..dccdea9 100644
--- a/lib/librarian/puppet/source/forge.rb
+++ b/lib/librarian/puppet/source/forge.rb
@@ -14,20 +14,26 @@ module Librarian
           def initialize(source, name)
             self.source = source
             self.name = name
+            @dependencies = {}
           end
 
           def versions
+            return @versions if @versions
             data = api_call("#{name}.json")
             if data.nil?
               raise Error, "Unable to find module '#{name}' on #{source}"
             end
 
-            data['releases'].map { |r| r['version'] }.sort.reverse
+            @versions = data['releases'].map { |r| r['version'] }.sort.reverse
           end
 
           def dependencies(version)
+            return @dependencies[version] if @dependencies[version]
             data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
-            data[name].first['dependencies']
+            if data.nil?
+              raise Error, "Unable to find version #{version} for module '#{name}' on #{source}"
+            end
+            @dependencies[version] = data[name].first['dependencies']
           end
 
           def manifests
@@ -158,11 +164,14 @@ module Librarian
           def api_call(path)
             base_url = source.to_s
             resp = Net::HTTP.get_response(URI.parse("#{base_url}/#{path}"))
-            if resp.code.to_i != 200
+            case resp.code.to_i
+            when 404,410
               nil
-            else
+            when 200
               data = resp.body
               JSON.parse(data)
+            else
+              raise Error, "Error requesting #{base_url}/#{path}: [#{resp.code}] #{resp.body}"
             end
           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