mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[misc] Extracts Changelog Rake task to class
This commit is contained in:
parent
52c71b0223
commit
b10626ab8a
2 changed files with 100 additions and 84 deletions
86
Rakefile
86
Rakefile
|
@ -181,91 +181,9 @@ YARD::Rake::YardocTask.new do |t|
|
|||
t.options = ["--output-dir", YARDOC_LOCATION, "--title", "#{name} #{version}"]
|
||||
end
|
||||
|
||||
task :changelog do
|
||||
timestamp = Time.now.utc.strftime('%m/%d/%Y')
|
||||
sha = `git log | head -1`.split(' ').last
|
||||
changelog = ["#{version} #{timestamp} #{sha}"]
|
||||
changelog << ('=' * changelog[0].length)
|
||||
changelog << ''
|
||||
require "fog/rake/changelog_task"
|
||||
Fog::Rake::ChangelogTask.new
|
||||
|
||||
require 'multi_json'
|
||||
github_repo_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog').body)
|
||||
data = github_repo_data.reject {|key, value| !['forks', 'open_issues', 'watchers'].include?(key)}
|
||||
github_collaborator_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog/collaborators').body)
|
||||
data['collaborators'] = github_collaborator_data.length
|
||||
rubygems_data = Fog::JSON.decode(Excon.get('https://rubygems.org/api/v1/gems/fog.json').body)
|
||||
data['downloads'] = rubygems_data['downloads']
|
||||
stats = []
|
||||
for key in data.keys.sort
|
||||
stats << "'#{key}' => #{data[key]}"
|
||||
end
|
||||
changelog << "Stats! { #{stats.join(', ')} }"
|
||||
changelog << ''
|
||||
|
||||
last_sha = `cat changelog.txt | head -1`.split(' ').last
|
||||
shortlog = `git shortlog #{last_sha}..HEAD`
|
||||
changes = {}
|
||||
committers = {}
|
||||
for line in shortlog.split("\n")
|
||||
if line =~ /^\S/
|
||||
committer = line.split(' (', 2).first
|
||||
committers[committer] = 0
|
||||
elsif line =~ /^\s*((Merge.*)|(Release.*))?$/
|
||||
# skip empty lines, Merge and Release commits
|
||||
else
|
||||
unless line[-1..-1] == '.'
|
||||
line << '.'
|
||||
end
|
||||
line.lstrip!
|
||||
line.gsub!(/^\[([^\]]*)\] /, '')
|
||||
tag = $1 || 'misc'
|
||||
changes[tag] ||= []
|
||||
changes[tag] << (line << ' thanks ' << committer)
|
||||
committers[committer] += 1
|
||||
end
|
||||
end
|
||||
|
||||
for committer, commits in committers.to_a.sort {|x,y| y[1] <=> x[1]}
|
||||
if [
|
||||
'Aaron Suggs',
|
||||
'Brian Hartsock',
|
||||
'Christopher Oliver',
|
||||
'Decklin Foster',
|
||||
'Dylan Egan',
|
||||
'geemus',
|
||||
'Henry Addison',
|
||||
'Kevin Menard',
|
||||
'Lincoln Stoll',
|
||||
'Luqman Amjad',
|
||||
'Michael Zeng',
|
||||
'Nick Osborn',
|
||||
'nightshade427',
|
||||
'Patrick Debois',
|
||||
'Stepan G. Fedorov',
|
||||
'Wesley Beary'
|
||||
].include?(committer)
|
||||
next
|
||||
end
|
||||
changelog << "MVP! #{committer}"
|
||||
changelog << ''
|
||||
break
|
||||
end
|
||||
|
||||
for tag in changes.keys.sort
|
||||
changelog << ('[' << tag << ']')
|
||||
for commit in changes[tag]
|
||||
changelog << (' ' << commit)
|
||||
end
|
||||
changelog << ''
|
||||
end
|
||||
|
||||
old_changelog = File.read('changelog.txt')
|
||||
File.open('changelog.txt', 'w') do |file|
|
||||
file.write(changelog.join("\n"))
|
||||
file.write("\n\n")
|
||||
file.write(old_changelog)
|
||||
end
|
||||
end
|
||||
|
||||
task :docs do
|
||||
Rake::Task[:supported_services_docs].invoke
|
||||
|
|
98
lib/fog/rake/changelog_task.rb
Normal file
98
lib/fog/rake/changelog_task.rb
Normal file
|
@ -0,0 +1,98 @@
|
|||
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
|
||||
timestamp = Time.now.utc.strftime('%m/%d/%Y')
|
||||
sha = `git log | head -1`.split(' ').last
|
||||
changelog = ["#{Fog::VERSION} #{timestamp} #{sha}"]
|
||||
changelog << ('=' * changelog[0].length)
|
||||
changelog << ''
|
||||
|
||||
require 'multi_json'
|
||||
github_repo_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog').body)
|
||||
data = github_repo_data.reject {|key, value| !['forks', 'open_issues', 'watchers'].include?(key)}
|
||||
github_collaborator_data = Fog::JSON.decode(Excon.get('https://api.github.com/repos/fog/fog/collaborators').body)
|
||||
data['collaborators'] = github_collaborator_data.length
|
||||
rubygems_data = Fog::JSON.decode(Excon.get('https://rubygems.org/api/v1/gems/fog.json').body)
|
||||
data['downloads'] = rubygems_data['downloads']
|
||||
stats = []
|
||||
for key in data.keys.sort
|
||||
stats << "'#{key}' => #{data[key]}"
|
||||
end
|
||||
changelog << "Stats! { #{stats.join(', ')} }"
|
||||
changelog << ''
|
||||
|
||||
last_sha = `cat changelog.txt | head -1`.split(' ').last
|
||||
shortlog = `git shortlog #{last_sha}..HEAD`
|
||||
changes = {}
|
||||
committers = {}
|
||||
for line in shortlog.split("\n")
|
||||
if line =~ /^\S/
|
||||
committer = line.split(' (', 2).first
|
||||
committers[committer] = 0
|
||||
elsif line =~ /^\s*((Merge.*)|(Release.*))?$/
|
||||
# skip empty lines, Merge and Release commits
|
||||
else
|
||||
unless line[-1..-1] == '.'
|
||||
line << '.'
|
||||
end
|
||||
line.lstrip!
|
||||
line.gsub!(/^\[([^\]]*)\] /, '')
|
||||
tag = $1 || 'misc'
|
||||
changes[tag] ||= []
|
||||
changes[tag] << (line << ' thanks ' << committer)
|
||||
committers[committer] += 1
|
||||
end
|
||||
end
|
||||
|
||||
for committer, commits in committers.to_a.sort {|x,y| y[1] <=> x[1]}
|
||||
if [
|
||||
'Aaron Suggs',
|
||||
'Brian Hartsock',
|
||||
'Christopher Oliver',
|
||||
'Decklin Foster',
|
||||
'Dylan Egan',
|
||||
'geemus',
|
||||
'Henry Addison',
|
||||
'Kevin Menard',
|
||||
'Lincoln Stoll',
|
||||
'Luqman Amjad',
|
||||
'Michael Zeng',
|
||||
'Nick Osborn',
|
||||
'nightshade427',
|
||||
'Patrick Debois',
|
||||
'Stepan G. Fedorov',
|
||||
'Wesley Beary'
|
||||
].include?(committer)
|
||||
next
|
||||
end
|
||||
changelog << "MVP! #{committer}"
|
||||
changelog << ''
|
||||
break
|
||||
end
|
||||
|
||||
for tag in changes.keys.sort
|
||||
changelog << ('[' << tag << ']')
|
||||
for commit in changes[tag]
|
||||
changelog << (' ' << commit)
|
||||
end
|
||||
changelog << ''
|
||||
end
|
||||
|
||||
old_changelog = File.read('changelog.txt')
|
||||
File.open('changelog.txt', 'w') do |file|
|
||||
file.write(changelog.join("\n"))
|
||||
file.write("\n\n")
|
||||
file.write(old_changelog)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue