Skip to content

Instantly share code, notes, and snippets.

@leemour
Forked from cdesch/rake task
Last active November 28, 2018 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemour/ca233abb711a6a34e64c5208b621240a to your computer and use it in GitHub Desktop.
Save leemour/ca233abb711a6a34e64c5208b621240a to your computer and use it in GitHub Desktop.
Ruby git CHANGELOG generator
namespace :changelog do
# simple rake task to output a changelog between two commits, tags ...
# output is formatted simply, commits are grouped under each author name
#
desc "generate changelog with nice clean output"
task :generate, :since_c, :until_c do |t, args|
since_c = args[:since_c] || `git tag | head -1`.chomp
until_c = args[:until_c] || `git rev-parse --short HEAD`
cmd=`git log --pretty='format:%ci::%an <%ae>::%s::%H' --after=#{since_c} --before=#{until_c}`
entries = {}
changelog_content = ""
cmd.split("\n").each do |entry|
date, author, subject, hash = entry.chomp.split("::")
entries[author] = Array.new unless entries[author]
day = date.split(" ").first
entries[author] << "#{subject} (#{hash})" unless subject =~ /Merge/
end
# generate clean output
entries.keys.each do |author|
changelog_content += author + "\n"
entries[author].reverse.each { |entry| changelog_content += " * #{entry}\n" }
end
puts changelog_content
end
end
#!/usr/bin/env ruby
# output a minimal changelog using git commit first line
# first and second args will be used as "since".."until" args for git log command
# based on http://snipplr.com/view.php?codeview&id=6261
# output is formatted simply, commits are grouped under each author name
#
cmd=`git log --pretty='format:%ci::%an <%ae>::%s::%H' --after=#{ARGV[0]} --before#{ARGV[1]}`
entries = Hash.new
changelog_content = String.new
cmd.split("\n").each do |entry|
date, author, subject, hash = entry.chomp.split("::")
entries[author] = Array.new unless entries[author]
day = date.split(" ").first
entries[author] << "#{subject} (#{hash})" unless subject =~ /Merge/
end
# generate clean output
entries.keys.each do |author|
changelog_content += author + "\n"
entries[author].reverse.each { |entry| changelog_content += "\t* #{entry}\n" }
end
puts changelog_content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment