# File lib/librarian/puppet/source/githubtarball.rb, line 73 def cache_path @cache_path ||= source.cache_path.join(name) end
# File lib/librarian/puppet/source/githubtarball.rb, line 85 def cache_version_unpacked!(version) path = version_unpacked_cache_path(version) return if path.directory? path.mkpath target = vendored?(source.uri, version) ? vendored_path(source.uri, version) : name Librarian::Posix.run!(%{tar xzf #{target} -C #{path}}) end
# File lib/librarian/puppet/source/githubtarball.rb, line 126 def clean_up_old_cached_versions(name) Dir["#{environment.vendor_cache}/#{name.sub('/', '-')}*.tar.gz"].each do |old_version| FileUtils.rm old_version end end
# File lib/librarian/puppet/source/githubtarball.rb, line 69 def environment source.environment end
# File lib/librarian/puppet/source/githubtarball.rb, line 81 def hexdigest(value) Digest::MD5.hexdigest(value) end
# File lib/librarian/puppet/source/githubtarball.rb, line 52 def install_version!(version, install_path) if environment.local? && !vendored?(source.uri, version) raise Error, "Could not find a local copy of #{source.uri} at #{version}." end vendor_cache(source.uri, version) unless vendored?(source.uri, version) cache_version_unpacked! version if install_path.exist? install_path.rmtree end unpacked_path = version_unpacked_cache_path(version).children.first cp_r(unpacked_path, install_path) end
# File lib/librarian/puppet/source/githubtarball.rb, line 46 def manifests versions.map do |version| Manifest.new(source, name, version) end end
# File lib/librarian/puppet/source/githubtarball.rb, line 105 def vendor_cache(name, version) clean_up_old_cached_versions(name) url = "https://api.github.com/repos/#{name}/tarball/#{version}" url << "?access_token=#{ENV['GITHUB_API_TOKEN']}" if ENV['GITHUB_API_TOKEN'] File.open(vendored_path(name, version).to_s, 'wb') do |f| begin debug { "Downloading <#{url}> to <#{f.path}>" } open(url, "User-Agent" => "librarian-puppet v#{Librarian::Puppet::VERSION}") do |res| while buffer = res.read(8192) f.write(buffer) end end rescue OpenURI::HTTPError => e raise e, "Error requesting <#{url}>: #{e.to_s}" end end end
# File lib/librarian/puppet/source/githubtarball.rb, line 96 def vendored?(name, version) vendored_path(name, version).exist? end
# File lib/librarian/puppet/source/githubtarball.rb, line 100 def vendored_path(name, version) environment.vendor_cache.mkpath environment.vendor_cache.join("#{name.sub("/", "-")}-#{version}.tar.gz") end
# File lib/librarian/puppet/source/githubtarball.rb, line 77 def version_unpacked_cache_path(version) cache_path.join('version').join(hexdigest(version.to_s)) end
# File lib/librarian/puppet/source/githubtarball.rb, line 28 def versions return @versions if @versions data = api_call("/repos/#{source.uri}/tags") if data.nil? raise Error, "Unable to find module '#{source.uri}' on https://github.com" end all_versions = data.map { |r| r['name'].gsub(/^v/, '') }.sort.reverse all_versions.delete_if do |version| version !~ /\A\d\.\d(\.\d.*)?\z/ end @versions = all_versions.compact debug { " Module #{name} found versions: #{@versions.join(", ")}" } @versions end
Generated with the Darkfish Rdoc Generator 2.