forked from bruce/puppet-vcsrepo
-
Notifications
You must be signed in to change notification settings - Fork 286
Open
Labels
Description
Use Case
Ability to checkout the latest release.
Describe the Solution You Would Like
Currently i made a custom lib to call Github API which is a simplified version of https://github.com/takumakume/puppet-github-release-properties :
require 'net/http'
require 'uri'
require 'json'
require 'stringio'
Puppet::Functions.create_function(:latest_git_tag) do
dispatch :latest_git_tag do
param 'String', :repo
end
def latest_git_tag(repo)
uri = URI.parse("https://api.github.com/repos/#{repo}/releases/latest")
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = 10
http.read_timeout = 15
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Content-Type'] = 'application/json'
request['Accept'] = 'application/vnd.github.v3+json'
request['Accept-Encoding'] = 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
response = http.request(request)
raise "#{response.code} #{response.message}: #{uri}" unless response.class == Net::HTTPOK
raw_body = if response.header['Content-Encoding'].eql?('gzip')
Zlib::GzipReader.new(StringIO.new(response.body)).read
else
response.body
end
return JSON.load(raw_body)['tag_name']
end
endThat I use like that :
vcsrepo { '/path/to/repo':
ensure => present,
provider => git,
source => 'git://example.com/repo.git',
revision => latest_git_tag('puppetlabs/puppetlabs-vcsrepo'),
}Describe Alternatives You've Considered
Downloading the tarball might be an option ?
Additional Context
This is a very simplified that fit my very specific needs (Github). Is there a better way ? Feedback is very welcome !