Skip to content

Instantly share code, notes, and snippets.

@jhsu
Created January 26, 2010 21:24
Show Gist options
  • Save jhsu/287254 to your computer and use it in GitHub Desktop.
Save jhsu/287254 to your computer and use it in GitHub Desktop.
namespace :do do
desc 'update changelog'
task :changelog do
# Pass in git opts by opts="-5" # -5 is number of commits
File.open('CHANGELOG', 'w+') do |changelog|
`git log -z --tags --abbrev-commit --no-color --format=fuller #{ENV['opts']}`.split("\0").each do |commit|
next if commit =~ /^Merge: \d*/
ref, author, author_time, commiter, commiter_time, _, title, message = commit.split("\n", 8)
next if author =~ /^Merge: \d*/
ref = ref[/commit ([0-9a-f]+)/, 1]
author = author[/Author: (.*)/, 1].strip
author_time = Time.parse(author_time[/AuthorDate: (.*)/, 1]).utc
commiter = commiter[/^Commit: (.*)/, 1].strip
commiter_time = Time.parse(commiter_time[/CommitDate: (.*)/, 1]).utc
title.strip!
title = "* #{title}" unless title =~ /^\s*\*/
message = "\t#{message}" unless title =~ /^\s*\*/
message.gsub!(/^\s*/, "")
message.gsub!(/\n/, " ")
puts [ref, author, author_time, commiter, commiter_time, title, message].join("\n") + "---\n"
# changelog.puts "[#{ref} | #{time}] #{author}"
changelog.puts "#{title}#{': ' + message if message && !message.blank?}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment