Skip to content

Instantly share code, notes, and snippets.

@eladb
Created June 10, 2014 09:20
Show Gist options
  • Save eladb/49e51bd872f92989674c to your computer and use it in GitHub Desktop.
Save eladb/49e51bd872f92989674c to your computer and use it in GitHub Desktop.
Markdown release notes since last bump commit with github links
#!/usr/bin/env ruby
#
# relnotes.rb
# Markdown release notes since last bump commit with github links
# Awesome for creating release notes for a release.
#
# Usage: ruby relnotes.rb [github-prefix]
#
# The script will extract all git commits since the last "bump commit" (a commit with the text "bump")
# and will generate a bulletted description of all the commits. If `github-prefix` is provided (e.g. "eladb/myrepo"),
# the script will replace "#nnn" and commit hashes with their github links.
#
def replace_github_issues(text, github_repo)
pos = 0
while true
m = text.match(/(#\d+)/, pos)
return text unless m
offset = m.offset(0)
before = text.slice(0, offset[0])
after = text.slice(offset[1], 99)
text = "#{before}[#{m[0]}](http://github.com/#{github_repo}/issues/#{m[0][1..-1]})#{after}"
pos = offset[1]
end
end
github_repo = ARGV[0]
last_bump = `git --no-pager log --grep bump -i -n1 --pretty=format:%H`
commits = `git --no-pager log --pretty=format:'%h\t%s\t%an\t' #{last_bump}..HEAD`.split("\n").map do |line|
hash, subject, author = line.split("\t")
# if subject contains an issue number, convert it into a link
# subject.to_enum(:scan, /(#\d+)/).map { Regexp.last_match }.each do |m|
subject = replace_github_issues(subject, github_repo) if github_repo
{
:hash => hash,
:subject => subject,
:author => author,
:commit_link => github_repo && "https://github.com/#{github_repo}/commit/#{hash}",
}
end
commits.each do |commit|
if commit[:commit_link]
puts " - [#{commit[:hash]}](#{commit[:commit_link]}): #{commit[:subject].capitalize} (_#{commit[:author]}_)"
else
puts " - #{commit[:hash]}: #{commit[:subject].capitalize} (_#{commit[:author]}_)"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment