2012-11-10 20:33:12 -05:00
|
|
|
require "rake"
|
|
|
|
require "rake/tasklib"
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Rake
|
|
|
|
class ChangelogTask < ::Rake::TaskLib
|
|
|
|
def initialize
|
|
|
|
desc "Update the changelog since the last release"
|
|
|
|
task(:changelog) do
|
|
|
|
|
2014-03-24 10:12:19 -04:00
|
|
|
@changelog = []
|
2014-03-25 09:23:12 -04:00
|
|
|
@changelog << release_header
|
2014-03-24 10:12:19 -04:00
|
|
|
|
|
|
|
process_commits
|
|
|
|
|
|
|
|
@changelog << "**MVP!** #{mvp}" if mvp
|
|
|
|
@changelog << blank_line
|
|
|
|
|
|
|
|
add_commits_to_changelog
|
|
|
|
save_changelog
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2014-03-25 09:23:12 -04:00
|
|
|
def release_header
|
|
|
|
<<-HEREDOC
|
|
|
|
## #{Fog::VERSION} #{timestamp}
|
|
|
|
*Hash* #{sha}
|
|
|
|
|
|
|
|
Statistic | Value
|
|
|
|
------------- | --------:
|
|
|
|
Collaborators | #{collaborators}
|
|
|
|
Downloads | #{downloads}
|
|
|
|
Forks | #{forks}
|
|
|
|
Open Issues | #{open_issues}
|
|
|
|
Watchers | #{watchers}
|
|
|
|
HEREDOC
|
|
|
|
end
|
|
|
|
|
2014-03-24 10:12:19 -04:00
|
|
|
def save_changelog
|
|
|
|
old_changelog = File.read('CHANGELOG.md')
|
|
|
|
File.open('CHANGELOG.md', 'w') do |file|
|
|
|
|
file.write(@changelog.join("\n"))
|
|
|
|
file.write("\n\n")
|
|
|
|
file.write(old_changelog)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def blank_line
|
|
|
|
''
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_commits_to_changelog
|
|
|
|
@changes.keys.sort.each do |tag|
|
|
|
|
@changelog << "#### [#{tag}]"
|
|
|
|
@changes[tag].each do |commit|
|
|
|
|
@changelog << "* #{commit}"
|
2012-11-10 20:33:12 -05:00
|
|
|
end
|
2014-03-24 10:12:19 -04:00
|
|
|
@changelog << blank_line
|
|
|
|
end
|
|
|
|
end
|
2012-11-10 20:33:12 -05:00
|
|
|
|
2014-03-24 10:12:19 -04:00
|
|
|
def process_commits
|
|
|
|
shortlog = `git shortlog #{last_release_sha}..HEAD`
|
|
|
|
@changes = {}
|
|
|
|
@committers = {}
|
|
|
|
@committer = nil
|
|
|
|
shortlog.split("\n").each do |line|
|
|
|
|
@current_line = line
|
|
|
|
if committer_line?
|
|
|
|
@committer = committer_match[1]
|
|
|
|
add_committer
|
|
|
|
elsif !release_merge_line?
|
|
|
|
add_period_if_necessary
|
|
|
|
@current_line.lstrip!
|
|
|
|
add_commit_line
|
|
|
|
increment_commits
|
2012-11-10 20:33:12 -05:00
|
|
|
end
|
2014-03-24 10:12:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_commit_line
|
|
|
|
@current_line.gsub!(/^\[([^\]]*)\] /, '')
|
|
|
|
tag = $1 || 'misc'
|
|
|
|
@changes[tag] ||= []
|
|
|
|
@changes[tag] << "#{@current_line} thanks #{@committer}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def increment_commits
|
|
|
|
@committers[@committer] += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_committer
|
|
|
|
@committers[@committer] = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def committers_sorted_by_commits
|
|
|
|
committer_pairs = @committers.to_a.sort {|x,y| y[1] <=> x[1]}
|
|
|
|
committer_pairs.reject! {|pair| pair.last < 1 }
|
2014-05-22 21:40:43 -04:00
|
|
|
committer_pairs.map {|pair| pair.first }
|
2014-03-24 10:12:19 -04:00
|
|
|
end
|
|
|
|
|
2014-04-17 15:08:49 -04:00
|
|
|
def former_mvp?(committer)
|
2014-03-24 10:12:19 -04:00
|
|
|
[
|
|
|
|
'Aaron Suggs',
|
2014-07-17 09:31:26 -04:00
|
|
|
'ller', #"Achim Ledermüller" UTF-8 fail?
|
2014-03-24 10:12:19 -04:00
|
|
|
'Ash Wilson',
|
2014-04-17 15:08:49 -04:00
|
|
|
'Benson Kalahar',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Brian Hartsock',
|
2015-04-02 16:44:36 -04:00
|
|
|
'Chris Luo',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Chris Roberts',
|
|
|
|
'Christopher Oliver',
|
2014-12-12 17:25:28 -05:00
|
|
|
'Colin Hebert',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Daniel Reichert',
|
2015-08-12 14:36:00 -04:00
|
|
|
'Darren Hague',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Decklin Foster',
|
|
|
|
'Dylan Egan',
|
|
|
|
'Erik Michaels-Ober',
|
2014-11-18 11:01:16 -05:00
|
|
|
'Frederick Cheung',
|
2014-03-24 10:12:19 -04:00
|
|
|
'geemus',
|
|
|
|
'Henry Addison',
|
|
|
|
'James Bence',
|
2015-05-07 14:40:15 -04:00
|
|
|
'Josef Stribny',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Kevin Menard',
|
|
|
|
'Kevin Olbrich',
|
|
|
|
'Kyle Rames',
|
2015-07-02 16:50:32 -04:00
|
|
|
'Ladislav Smola',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Lincoln Stoll',
|
|
|
|
'Luqman Amjad',
|
2014-10-09 10:20:06 -04:00
|
|
|
'Michael Hale',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Michael Zeng',
|
|
|
|
'Mike Hagedorn',
|
|
|
|
'Mike Pountney',
|
|
|
|
'Nat Welch',
|
|
|
|
'Nick Osborn',
|
|
|
|
'nightshade427',
|
2015-09-03 15:38:39 -04:00
|
|
|
'Oleg Vivtash',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Patrick Debois',
|
|
|
|
'Paul Thornthwaite',
|
2015-01-12 11:47:43 -05:00
|
|
|
'Paulo Henrique Lopes Ribeiro',
|
2015-02-19 17:13:01 -05:00
|
|
|
'Peter Souter',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Rodrigo Estebanez',
|
|
|
|
'Rupak Ganguly',
|
|
|
|
'Stepan G. Fedorov',
|
2015-06-04 20:25:04 -04:00
|
|
|
'TerryHowe',
|
2014-03-24 10:12:19 -04:00
|
|
|
'Wesley Beary'
|
|
|
|
].include?(committer)
|
|
|
|
end
|
2012-11-10 20:33:12 -05:00
|
|
|
|
2014-03-24 10:12:19 -04:00
|
|
|
def mvp
|
|
|
|
return @mvp if @mvp
|
|
|
|
committers_sorted_by_commits.each do |committer|
|
2014-04-17 15:08:49 -04:00
|
|
|
unless former_mvp?(committer)
|
2014-03-24 10:12:19 -04:00
|
|
|
@mvp = committer
|
|
|
|
return @mvp
|
2012-11-10 20:33:12 -05:00
|
|
|
end
|
|
|
|
end
|
2014-03-24 10:12:19 -04:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_period_if_necessary
|
|
|
|
@current_line << "." unless @current_line[-1] == '.'
|
|
|
|
end
|
|
|
|
|
|
|
|
def release_merge_line?
|
|
|
|
@current_line =~ /^\s*((Merge.*)|(Release.*))?$/
|
|
|
|
end
|
|
|
|
|
|
|
|
def committer_line?
|
|
|
|
committer_match != nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def committer_match
|
|
|
|
@current_line.match /([\w\s]+)\s+\(\d+\)/
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_release_sha
|
2015-04-02 16:44:36 -04:00
|
|
|
`cat CHANGELOG.md | head -2`.split(' ').last
|
2014-03-24 10:12:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def downloads
|
|
|
|
repsonse = Excon.get('https://rubygems.org/api/v1/gems/fog.json')
|
|
|
|
data = Fog::JSON.decode(repsonse.body)
|
|
|
|
data['downloads']
|
|
|
|
end
|
|
|
|
|
|
|
|
def collaborators
|
|
|
|
response = Excon.get('https://api.github.com/repos/fog/fog/collaborators', :headers => {'User-Agent' => 'geemus'})
|
|
|
|
data = Fog::JSON.decode(response.body)
|
|
|
|
data.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def forks
|
|
|
|
repo_metadata['forks']
|
|
|
|
end
|
|
|
|
|
|
|
|
def open_issues
|
|
|
|
repo_metadata['open_issues']
|
|
|
|
end
|
|
|
|
|
|
|
|
def watchers
|
|
|
|
repo_metadata['watchers']
|
2012-11-10 20:33:12 -05:00
|
|
|
end
|
2014-03-24 10:12:19 -04:00
|
|
|
|
|
|
|
def repo_metadata
|
|
|
|
return @repo_metadata if @repo_metadata
|
|
|
|
response = Excon.get('https://api.github.com/repos/fog/fog', :headers => {'User-Agent' => 'geemus'})
|
|
|
|
data = Fog::JSON.decode(response.body)
|
|
|
|
@repo_metadata = data.select {|key, value| ['forks', 'open_issues', 'watchers'].include?(key)}
|
|
|
|
end
|
|
|
|
|
|
|
|
def sha
|
|
|
|
`git log | head -1`.split(' ').last
|
|
|
|
end
|
|
|
|
|
|
|
|
def timestamp
|
|
|
|
@time ||= Time.now.utc.strftime('%m/%d/%Y')
|
|
|
|
end
|
2012-11-10 20:33:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|