-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathrelease_planning.rb
More file actions
executable file
·115 lines (94 loc) · 3.91 KB
/
Copy pathrelease_planning.rb
File metadata and controls
executable file
·115 lines (94 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'erb'
require 'optparse'
require_relative 'octokit_utils'
class PuppetModule
attr_accessor :name, :namespace, :tag_date, :commits, :downloads
def initialize(name, namespace, tag_date, commits, downloads = 0)
@name = name
@namespace = namespace
@tag_date = tag_date
@commits = commits
@downloads = downloads
end
end
puppet_modules = []
def number_of_downloads(module_name)
uri = URI.parse("https://forgeapi.puppetlabs.com/v3/modules/#{module_name}")
request = Net::HTTP::Get.new(uri.path)
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http| # pay attention to use_ssl if you need it
http.request(request)
end
output = response.body
parsed = JSON.parse(output)
puts parsed
begin
parsed['current_release']['downloads']
rescue NoMethodError
"Error number of downloads #{module_name}"
end
end
options = {}
options[:oauth] = ENV['GITHUB_COMMUNITY_TOKEN'] if ENV['GITHUB_COMMUNITY_TOKEN']
parser = OptionParser.new do |opts|
opts.banner = 'Usage: release_planning.rb [options]'
opts.on('-c', '--commit-threshold NUM', 'Number of commits since release') { |v| options[:commits] = v.to_i }
opts.on('-g', '--tag-regex REGEX', 'Tag regex') { |v| options[:tag_regex] = v }
opts.on('-m', '--time-threshold DAYS', 'Days since release') { |v| options[:time] = v.to_i }
opts.on('-f', '--file NAME', String, 'Module file list') { |v| options[:file] = v }
opts.on('-t', '--oauth-token TOKEN', 'OAuth token. Required.') { |v| options[:oauth] = v }
opts.on('-v', '--verbose', 'More output') { options[:verbose] = true }
opts.on('-o', '--output', 'Creates html+json output') { options[:output] = true }
end
parser.parse!
options[:file] = 'modules.json' if options[:file].nil?
missing = []
missing << '-t' if options[:oauth].nil?
missing << '-m or -c' if options[:time].nil? && options[:commits].nil?
unless missing.empty?
puts "Missing options: #{missing.join(', ')}"
puts parser
exit
end
options[:tag_regex] = '.*' if options[:tag_regex].nil?
util = OctokitUtils.new(options[:oauth])
parsed = util.load_module_list(options[:file])
repo_data = []
parsed.each do |m|
begin
latest_tag = util.fetch_tags("#{m['github_namespace']}/#{m['repo_name']}", options).first
tag_ref = util.ref_from_tag(latest_tag)
date_of_tag = util.date_of_ref("#{m['github_namespace']}/#{m['repo_name']}", tag_ref)
commits_since_tag = util.commits_since_date("#{m['github_namespace']}/#{m['repo_name']}", date_of_tag)
repo_data << { 'repo' => "#{m['github_namespace']}/#{m['repo_name']}", 'date' => date_of_tag, 'commits' => commits_since_tag, 'downloads' => number_of_downloads(m['forge_name']) }
puppet_modules << PuppetModule.new(repo, "#{m['github_namespace']}/#{m['repo_name']}", date_of_tag, commits_since_tag)
rescue StandardError
puts "Unable to fetch tags for #{options[:namespace]}/#{repo}" if options[:verbose]
end
end
puppet_modules.each { |puppet_module1| puts puppet_module1 }
due_by_commit = repo_data.select { |x| x['commits'] > options[:commits] } if options[:commits]
if options[:time]
threshold = Time.now - options[:time]
due_by_time = repo_data.select { |x| x['date'] < threshold }
end
due_for_release = if due_by_commit && due_by_time
due_by_commit & due_by_time
elsif due_by_commit
due_by_commit
else
due_by_time
end
due_for_release.each do |entry|
puts "#{entry['repo']} is due for release. Last release was tagged on #{entry['date']} and there have been #{entry['commits']} commits since then."
end
html = ERB.new(File.read('release_planning.html.erb')).result(binding)
if options[:output]
File.open('ModulesRelease.html', 'wb') do |f|
f.puts(html)
end
File.open('ModulesRelease.json', 'wb') do |f|
JSON.dump(due_for_release, f)
end
end