Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 219 lines (182 sloc) 6.478 kb
72aa9fd @donv # Sorry for the HUGE commit!
donv authored
1 require 'rubygems'
2 require 'bundler/gem_tasks'
f9542c9 @donv * Added a bit of Bundler stuff
donv authored
3 require 'rake/testtask'
791bb19 @donv * Removed hoe to simplify the project setup.
donv authored
4 require 'rake/clean'
b5788a4 @topfunky First import from Subversion
authored
5
72aa9fd @donv # Sorry for the HUGE commit!
donv authored
6 CLEAN << %w(pkg test/output/*)
b5788a4 @topfunky First import from Subversion
authored
7
72aa9fd @donv # Sorry for the HUGE commit!
donv authored
8 desc 'Run tests'
f9542c9 @donv * Added a bit of Bundler stuff
donv authored
9 task :default => :test
10
4d673af @donv * Remove Gemfile.lock to allow travis-ci to pick the best match.
donv authored
11 task :gem => :build
12
1dffdaa @donv * Removed unnecessary config of test task.
donv authored
13 Rake::TestTask.new
b5788a4 @topfunky First import from Subversion
authored
14
15 namespace :test do
72aa9fd @donv # Sorry for the HUGE commit!
donv authored
16 desc 'Run mini tests'
b5788a4 @topfunky First import from Subversion
authored
17 task :mini => :clean do
18 Dir['test/test_mini*'].each do |file|
19 system "ruby #{file}"
20 end
21 end
22 end
ee96f0c @donv * Bumped version to 0.4.0 since we have new features.
donv authored
23
ebafa58 @donv * Moved task description to correct location.
donv authored
24 desc 'Generate release docs for a given milestone'
ee96f0c @donv * Bumped version to 0.4.0 since we have new features.
donv authored
25 task :release_docs do
26 raise "\n This task requires Ruby 1.9 or newer to parse JSON as YAML.\n\n" if RUBY_VERSION == '1.8.7'
27 categories, grouped_issues, milestone, milestone_description, milestone_name = get_github_issues
28
29 puts '=' * 80
30 puts
31 release_doc = <<EOF
32 Subject: [ANN] Gruff #{milestone_name} released!
33
34 The Gruff team is pleased to announce the release of Gruff #{milestone_name}.
35
36 New in version #{milestone_name}:
37
38 #{milestone_description}
39
40 #{(categories.keys & grouped_issues.keys).map do |cat|
41 "#{cat}:\n
42 #{grouped_issues[cat].map { |i| wrap(%Q{* Issue ##{i['number']} #{i['title']}},2) }.join("\n")}
43 "
44 end.join("\n")}
45 You can find a complete list of issues here:
46
47 * https://github.com/topfunky/gruff/issues?state=closed&milestone=#{milestone}
48
49
50 Installation:
51
52 gem install gruff
53
54 You can find an introductory tutorial at
55 https://github.com/topfunky/gruff
56
57 Enjoy!
58
59
60 --
61 The Gruff Team
62 EOF
63
64 puts release_doc
65 puts
66 puts '=' * 80
67
68 unless Gem::Version.new(Gruff::VERSION).prerelease?
69 File.write('RELEASE.md', release_doc)
70 end
71 end
72
73 desc 'Fetch download stats form rubygems.org'
74 task :stats do
75 require 'time'
76 require 'date'
77 require 'rubygems'
78 require 'uri'
79 require 'net/http'
80 require 'net/https'
81 require 'openssl'
82 require 'yaml'
83 host = 'rubygems.org'
84 base_uri = "https://#{host}/api/v1"
85 https = Net::HTTP.new(host, 443)
86 https.use_ssl = true
87 https.verify_mode = OpenSSL::SSL::VERIFY_NONE
88
89 counts_per_month = Hash.new { |h, k| h[k] = Hash.new { |mh, mk| mh[mk] = 0 } }
90 total = 0
91
92 %w{gruff}.each do |gem|
93 versions_uri = URI("#{base_uri}/versions/#{gem}.yaml")
94 req = Net::HTTP::Get.new(versions_uri.request_uri)
95 res = https.start { |http| http.request(req) }
96 versions = YAML.load(res.body).sort_by { |v| Gem::Version.new(v['number']) }
97 puts "\n#{gem}:\n#{versions.map { |v| "#{Time.parse(v['built_at']).strftime('%Y-%m-%d')} #{'%10s' % v['number']} #{v['downloads_count']}" }.join("\n")}"
98
99 versions.each do |v|
100 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}")
101 req = Net::HTTP::Get.new(downloads_uri.request_uri)
102 res = https.start { |http| http.request(req) }
103 counts = YAML.load(res.body)
104 counts.delete_if { |date_str, count| count == 0 }
105 counts.each do |date_str, count|
106 date = Date.parse(date_str)
107 counts_per_month[date.year][date.month] += count
108 total += count
109 end
110 print '.'; STDOUT.flush
111 end
112 puts
113 end
114
115 puts "\nDownloads statistics per month:"
116 years = counts_per_month.keys
117 puts "\n #{years.map { |year| '%6s:' % year }.join(' ')}"
118 (1..12).each do |month|
119 print "#{'%2d' % month}:"
120 years.each do |year|
121 count = counts_per_month[year][month]
122 print count > 0 ? '%8d' % count : ' ' * 8
123 end
124 puts
125 end
126
127 puts "\nTotal: #{total}\n\n"
128
129 puts "\nRubyGems download statistics per month:"
130 years = counts_per_month.keys
131 puts ' ' + years.map { |year| '%-12s' % year }.join
132 (0..20).each do |l|
133 print (l % 10 == 0) ? '%4d' % ((20-l) * 100) : ' '
134 years.each do |year|
135 (1..12).each do |month|
136 count = counts_per_month[year][month]
137 if [year, month] == [Date.today.year, Date.today.month]
138 count *= (Date.new(Date.today.year, Date.today.month, -1).day.to_f / Date.today.day).to_i
139 end
140 print count > ((20-l) * 100) ? '*' : ' '
141 end
142 end
143 puts
144 end
145 puts ' ' + years.map { |year| '%-12s' % year }.join
146
147 puts "\nTotal: #{total}\n\n"
148 end
149
150
151 def get_github_issues
152 puts 'GitHub login:'
153 begin
154 require 'rubygems'
155 require 'highline/import'
156 user = ask('login : ') { |q| q.echo = true }
157 pass = ask('password: ') { |q| q.echo = '*' }
158 rescue Exception
159 print 'user name: '; user = STDIN.gets.chomp
160 print ' password: '; pass = STDIN.gets.chomp
161 end
162 require 'uri'
163 require 'net/http'
164 require 'net/https'
165 require 'openssl'
166 require 'yaml'
167 host = 'api.github.com'
168 base_uri = "https://#{host}/repos/topfunky/gruff"
169 https = Net::HTTP.new(host, 443)
170 https.use_ssl = true
171 https.verify_mode = OpenSSL::SSL::VERIFY_NONE
172
173 milestone_uri = URI("#{base_uri}/milestones")
174 req = Net::HTTP::Get.new(milestone_uri.request_uri)
175 req.basic_auth(user, pass)
176 res = https.start { |http| http.request(req) }
177 milestones = YAML.load(res.body).sort_by { |i| Date.parse(i['due_on']) }
178 puts milestones.map { |m| "#{'%2d' % m['number']} #{m['title']}" }.join("\n")
179
180 if defined? ask
181 milestone = ask('milestone: ', Integer) { |q| q.echo = true }
182 else
183 print 'milestone: '; milestone = STDIN.gets.chomp
184 end
185
186 uri = URI("#{base_uri}/issues?milestone=#{milestone}&state=closed&per_page=1000")
187 req = Net::HTTP::Get.new(uri.request_uri)
188 req.basic_auth(user, pass)
189 res = https.start { |http| http.request(req) }
190 issues = YAML.load(res.body).sort_by { |i| i['number'] }
191 milestone_name = issues[0] ? issues[0]['milestone']['title'] : "No issues for milestone #{milestone}"
192 milestone_description = issues[0] ? issues[0]['milestone']['description'] : "No issues for milestone #{milestone}"
193 milestone_description = milestone_description.split("\r\n").map{|l|wrap l}.join("\r\n")
194 categories = {
195 'Features' => 'feature', 'Bugfixes' => 'bug', 'Support' => 'support',
196 'Documentation' => 'documentation', 'Pull requests' => nil,
197 'Internal' => 'internal', 'Rejected' => 'rejected', 'Other' => nil
198 }
199 grouped_issues = issues.group_by do |i|
200 labels = i['labels'].map { |l| l['name'] }
201 cat = nil
202 categories.each do |k, v|
203 if labels.include? v
204 cat = k
205 break
206 end
207 end
208 cat ||= i['pull_request'] && i['pull_request']['html_url'] && 'Pull requests'
209 cat ||= 'Other'
210 cat
211 end
212 return categories, grouped_issues, milestone, milestone_description, milestone_name
213 end
214
215 def wrap(string, indent = 0)
216 string.scan(/\S.{0,72}\S(?=\s|$)|\S+/).join("\n" + ' ' * indent)
217 end
218
Something went wrong with that request. Please try again.