[DRE-commits] [librarian-puppet] 25/97: Don't sort versions as strings. Reduce calls to API
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 1f47e364f7cb633a798b636a2605fa0055b8f9ad
Author: Carlos Sanchez <csanchez at maestrodev.com>
Date: Wed Jul 10 11:57:35 2013 +0200
Don't sort versions as strings. Reduce calls to API
Versions were returned in the wrong order because it wasn't using the right Forge API
Call the Forge API once for each module only and cache the data
---
features/update.feature | 3 +--
lib/librarian/puppet/source/forge.rb | 35 ++++++++++++++++++-----------------
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/features/update.feature b/features/update.feature
index f2d6764..3f3d903 100644
--- a/features/update.feature
+++ b/features/update.feature
@@ -80,9 +80,8 @@ Feature: cli/update
Then the exit status should be 1
And the output should contain "Unable to find module stdlib"
- @pending
Scenario: Updating a module to a .10 release to ensure versions are correctly ordered
- Given PENDING a file named "Puppetfile" with:
+ Given a file named "Puppetfile" with:
"""
forge "http://forge.puppetlabs.com"
diff --git a/lib/librarian/puppet/source/forge.rb b/lib/librarian/puppet/source/forge.rb
index ac93b6c..e186fb5 100644
--- a/lib/librarian/puppet/source/forge.rb
+++ b/lib/librarian/puppet/source/forge.rb
@@ -13,26 +13,18 @@ module Librarian
def initialize(source, name)
self.source = source
self.name = name
- @dependencies = {}
+ @api_data = nil
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
-
- @versions = data['releases'].map { |r| r['version'] }.sort.reverse
+ @versions = api_data[name].map { |r| r['version'] }.reverse
+ debug { " Module #{name} found versions: #{@versions.join(", ")}" }
+ @versions
end
def dependencies(version)
- return @dependencies[version] if @dependencies[version]
- data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
- if data.nil?
- raise Error, "Unable to find version #{version} for module '#{name}' on #{source}"
- end
- @dependencies[version] = data[name].first['dependencies']
+ api_data[name].detect{|x| x['version'] == version.to_s}['dependencies']
end
def manifests
@@ -131,8 +123,7 @@ module Librarian
end
def vendor_cache(name, version)
- data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
- info = data[name].detect {|h| h['version'] == version.to_s }
+ info = api_data[name].detect {|h| h['version'] == version.to_s }
File.open(vendored_path(name, version).to_s, 'w') do |f|
open("#{source}#{info['file']}") do |input|
while (buffer = input.read)
@@ -147,11 +138,21 @@ module Librarian
end
private
+ def api_data
+ return @api_data if @api_data
+ # call API and cache data
+ @api_data = api_call(name)
+ if @api_data.nil?
+ raise Error, "Unable to find module '#{name}' on #{source}"
+ end
+ @api_data
+ end
- def api_call(path)
+ def api_call(module_name)
+ debug { "Querying Forge API for module #{name}" }
base_url = source.uri
begin
- data = open("#{base_url}/#{path}") {|f| f.read}
+ data = open("#{base_url}/api/v1/releases.json?module=#{module_name}") {|f| f.read}
JSON.parse(data)
rescue OpenURI::HTTPError => e
case e.io.status[0].to_i
--
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