forked from topfunky/gruff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
218 lines (182 loc) · 6.33 KB
/
Rakefile
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
require 'rubygems'
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rake/clean'
CLEAN << %w(pkg test/output/*)
desc 'Run tests'
task :default => :test
task :gem => :build
Rake::TestTask.new
namespace :test do
desc 'Run mini tests'
task :mini => :clean do
Dir['test/test_mini*'].each do |file|
system "ruby #{file}"
end
end
end
desc 'Generate release docs for a given milestone'
task :release_docs do
raise "\n This task requires Ruby 1.9 or newer to parse JSON as YAML.\n\n" if RUBY_VERSION == '1.8.7'
categories, grouped_issues, milestone, milestone_description, milestone_name = get_github_issues
puts '=' * 80
puts
release_doc = <<EOF
Subject: [ANN] Gruff #{milestone_name} released!
The Gruff team is pleased to announce the release of Gruff #{milestone_name}.
New in version #{milestone_name}:
#{milestone_description}
#{(categories.keys & grouped_issues.keys).map do |cat|
"#{cat}:\n
#{grouped_issues[cat].map { |i| wrap(%Q{* Issue ##{i['number']} #{i['title']}},2) }.join("\n")}
"
end.join("\n")}
You can find a complete list of issues here:
* https://github.com/topfunky/gruff/issues?state=closed&milestone=#{milestone}
Installation:
gem install gruff
You can find an introductory tutorial at
https://github.com/topfunky/gruff
Enjoy!
--
The Gruff Team
EOF
puts release_doc
puts
puts '=' * 80
unless Gem::Version.new(Gruff::VERSION).prerelease?
File.write('RELEASE.md', release_doc)
end
end
desc 'Fetch download stats form rubygems.org'
task :stats do
require 'time'
require 'date'
require 'rubygems'
require 'uri'
require 'net/http'
require 'net/https'
require 'openssl'
require 'yaml'
host = 'rubygems.org'
base_uri = "https://#{host}/api/v1"
https = Net::HTTP.new(host, 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
counts_per_month = Hash.new { |h, k| h[k] = Hash.new { |mh, mk| mh[mk] = 0 } }
total = 0
%w{gruff}.each do |gem|
versions_uri = URI("#{base_uri}/versions/#{gem}.yaml")
req = Net::HTTP::Get.new(versions_uri.request_uri)
res = https.start { |http| http.request(req) }
versions = YAML.load(res.body).sort_by { |v| Gem::Version.new(v['number']) }
puts "\n#{gem}:\n#{versions.map { |v| "#{Time.parse(v['built_at']).strftime('%Y-%m-%d')} #{'%10s' % v['number']} #{v['downloads_count']}" }.join("\n")}"
versions.each do |v|
downloads_uri = URI("#{base_uri}/versions/#{gem}-#{v['number']}/downloads/search.yaml?from=#{Time.parse(v['built_at']).strftime('%Y-%m-%d')}&to=#{Date.today}")
req = Net::HTTP::Get.new(downloads_uri.request_uri)
res = https.start { |http| http.request(req) }
counts = YAML.load(res.body)
counts.delete_if { |date_str, count| count == 0 }
counts.each do |date_str, count|
date = Date.parse(date_str)
counts_per_month[date.year][date.month] += count
total += count
end
print '.'; STDOUT.flush
end
puts
end
puts "\nDownloads statistics per month:"
years = counts_per_month.keys
puts "\n #{years.map { |year| '%6s:' % year }.join(' ')}"
(1..12).each do |month|
print "#{'%2d' % month}:"
years.each do |year|
count = counts_per_month[year][month]
print count > 0 ? '%8d' % count : ' ' * 8
end
puts
end
puts "\nTotal: #{total}\n\n"
puts "\nRubyGems download statistics per month:"
years = counts_per_month.keys
puts ' ' + years.map { |year| '%-12s' % year }.join
(0..20).each do |l|
print (l % 10 == 0) ? '%4d' % ((20-l) * 100) : ' '
years.each do |year|
(1..12).each do |month|
count = counts_per_month[year][month]
if [year, month] == [Date.today.year, Date.today.month]
count *= (Date.new(Date.today.year, Date.today.month, -1).day.to_f / Date.today.day).to_i
end
print count > ((20-l) * 100) ? '*' : ' '
end
end
puts
end
puts ' ' + years.map { |year| '%-12s' % year }.join
puts "\nTotal: #{total}\n\n"
end
def get_github_issues
puts 'GitHub login:'
begin
require 'rubygems'
require 'highline/import'
user = ask('login : ') { |q| q.echo = true }
pass = ask('password: ') { |q| q.echo = '*' }
rescue Exception
print 'user name: '; user = STDIN.gets.chomp
print ' password: '; pass = STDIN.gets.chomp
end
require 'uri'
require 'net/http'
require 'net/https'
require 'openssl'
require 'yaml'
host = 'api.github.com'
base_uri = "https://#{host}/repos/topfunky/gruff"
https = Net::HTTP.new(host, 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
milestone_uri = URI("#{base_uri}/milestones")
req = Net::HTTP::Get.new(milestone_uri.request_uri)
req.basic_auth(user, pass)
res = https.start { |http| http.request(req) }
milestones = YAML.load(res.body).sort_by { |i| Date.parse(i['due_on']) }
puts milestones.map { |m| "#{'%2d' % m['number']} #{m['title']}" }.join("\n")
if defined? ask
milestone = ask('milestone: ', Integer) { |q| q.echo = true }
else
print 'milestone: '; milestone = STDIN.gets.chomp
end
uri = URI("#{base_uri}/issues?milestone=#{milestone}&state=closed&per_page=1000")
req = Net::HTTP::Get.new(uri.request_uri)
req.basic_auth(user, pass)
res = https.start { |http| http.request(req) }
issues = YAML.load(res.body).sort_by { |i| i['number'] }
milestone_name = issues[0] ? issues[0]['milestone']['title'] : "No issues for milestone #{milestone}"
milestone_description = issues[0] ? issues[0]['milestone']['description'] : "No issues for milestone #{milestone}"
milestone_description = milestone_description.split("\r\n").map{|l|wrap l}.join("\r\n")
categories = {
'Features' => 'feature', 'Bugfixes' => 'bug', 'Support' => 'support',
'Documentation' => 'documentation', 'Pull requests' => nil,
'Internal' => 'internal', 'Rejected' => 'rejected', 'Other' => nil
}
grouped_issues = issues.group_by do |i|
labels = i['labels'].map { |l| l['name'] }
cat = nil
categories.each do |k, v|
if labels.include? v
cat = k
break
end
end
cat ||= i['pull_request'] && i['pull_request']['html_url'] && 'Pull requests'
cat ||= 'Other'
cat
end
return categories, grouped_issues, milestone, milestone_description, milestone_name
end
def wrap(string, indent = 0)
string.scan(/\S.{0,72}\S(?=\s|$)|\S+/).join("\n" + ' ' * indent)
end